Shlomi Fish avatar Shlomi Fish committed 2a26fd4

Bug fix.

Comments (0)

Files changed (1)

black-hole-solitaire/c-solver/black_hole_solver.c

     return BLACK_HOLE_SOLVER__SUCCESS;
 }
 
+static GCC_INLINE fcs_bool_t string_find_prefix(
+    const char * * s,
+    const char * const prefix
+)
+{
+    register size_t len = strlen(prefix);
+
+    if (strncmp(*s, prefix, len) != 0)
+    {
+        return FALSE;
+    }
+
+    (*s) += len;
+
+    return TRUE;
+}
 
 extern int DLLEXPORT black_hole_solver_read_board(
     black_hole_solver_instance_t * instance_proto,
     int bits_per_column
 )
 {
-    const char * s, * match;
+    const char * s;
     bhs_solver_t * solver;
     int ret_code, col_idx;
     int line_num = 1;
         s++;
     }
 
-    match = "Foundations: ";
-
 #define MYRET(code) \
     { \
         *error_line_number = line_num; \
         return code; \
     }
 
-    /* TODO : a bug - should be if (!strncmp(s, match, strlen(match)) */
-    if (!strcmp(s, match))
+    if (! string_find_prefix(&s, "Foundations: "))
     {
         MYRET (BLACK_HOLE_SOLVER__FOUNDATIONS_NOT_FOUND_AT_START);
     }
 
-    s += strlen(match);
-
     while (isspace(*s) && ((*s) != '\n'))
     {
         s++;
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.