h48

A prototype for an optimal Rubik's cube solver, work in progress.
git clone https://git.tronto.net/h48
Download | Log | Files | Refs | README | LICENSE

commit ea25a7ccad625c4e664dfd114147971b8a2677f3
parent a3a477870cdbdb4b9c4c8b403c09b13502291234
Author: Sebastiano Tronto <sebastiano@tronto.net>
Date:   Sat, 19 Oct 2024 19:29:59 +0200

Safer handling of corrupt data

Diffstat:
Msrc/nissy.c | 20+++++++++++++++++---
1 file changed, 17 insertions(+), 3 deletions(-)

diff --git a/src/nissy.c b/src/nissy.c @@ -13,10 +13,11 @@ #include "solvers/solvers.h" int parse_h48_solver(const char *, uint8_t [static 1], uint8_t [static 1]); -STATIC long long write_result(cube_t, char [static NISSY_SIZE_B32]); +STATIC bool checkdata(const char *, const tableinfo_t *); STATIC bool distribution_equal(const uint64_t [static INFO_DISTRIBUTION_LEN], const uint64_t [static INFO_DISTRIBUTION_LEN], uint8_t); -STATIC bool checkdata(const char *, const tableinfo_t *); +STATIC long long write_result(cube_t, char [static NISSY_SIZE_B32]); +STATIC size_t my_strnlen(const char *, size_t); #define GETCUBE_OPTIONS(S, F) { .option = S, .fix = F } struct { @@ -71,7 +72,8 @@ checkdata(const char *buf, const tableinfo_t *info) { uint64_t distr[INFO_DISTRIBUTION_LEN]; - if (info == NULL) { + if (info == NULL || my_strnlen(info->solver, INFO_SOLVER_STRLEN) + == INFO_SOLVER_STRLEN) { LOG("checkdata: error reading table info\n"); return false; } else if (!strncmp(info->solver, "cocsep", 6)) { @@ -122,6 +124,18 @@ write_result(cube_t cube, char result[static NISSY_SIZE_B32]) return NISSY_OK; } +STATIC size_t +my_strnlen(const char *str, size_t maxlen) +{ + size_t i; + + for (i = 0; i < maxlen; i++) + if (str[i] == '\0') + return i; + + return maxlen; +} + long long nissy_compose( const char cube[static NISSY_SIZE_B32],