Skip to content

Commit 3ee8d57

Browse files
committed
Fixes C code generation error with \0 code.
1 parent f223179 commit 3ee8d57

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/bin2cpp/ManagerGenerator.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -382,12 +382,12 @@ namespace bin2cpp
382382
fprintf(fout, "\n");
383383
fprintf(fout, "static inline bool bin2c_filemanager_is_root_directory(const char* path)\n");
384384
fprintf(fout, "{\n");
385-
fprintf(fout, " if ( path == NULL && path[0] == '\0' )\n");
385+
fprintf(fout, " if ( path == NULL && path[0] == '\\0' )\n");
386386
fprintf(fout, " return false;\n");
387387
fprintf(fout, "#if defined(_WIN32)\n");
388388
fprintf(fout, " bool is_drive_letter = ((path[0] >= 'a' && path[0] <= 'z') || (path[0] >= 'A' && path[0] <= 'Z'));\n");
389-
fprintf(fout, " if ( (is_drive_letter && path[1] == ':' && path[2] == '\0') || // test for C:\n");
390-
fprintf(fout, " (is_drive_letter && path[1] == ':' && path[2] == PATH_SEPARATOR_CHAR && path[3] == '\0') ) // test for C:\\ \n");
389+
fprintf(fout, " if ( (is_drive_letter && path[1] == ':' && path[2] == '\\0') || // test for C:\n");
390+
fprintf(fout, " (is_drive_letter && path[1] == ':' && path[2] == PATH_SEPARATOR_CHAR && path[3] == '\\0') ) // test for C:\\ \n");
391391
fprintf(fout, " return true;\n");
392392
fprintf(fout, "#else\n");
393393
fprintf(fout, " if ( path[0] == PATH_SEPARATOR_CHAR )\n");
@@ -403,11 +403,11 @@ namespace bin2cpp
403403
fprintf(fout, " char* accumulator = (char*)malloc(BIN2C_MAX_PATH);\n");
404404
fprintf(fout, " if ( accumulator == NULL )\n");
405405
fprintf(fout, " return false;\n");
406-
fprintf(fout, " accumulator[0] = '\0';\n");
406+
fprintf(fout, " accumulator[0] = '\\0';\n");
407407
fprintf(fout, " size_t length = strlen(file_path);\n");
408408
fprintf(fout, " for ( size_t i = 0; i < length; i++ )\n");
409409
fprintf(fout, " {\n");
410-
fprintf(fout, " if ( file_path[i] == PATH_SEPARATOR_CHAR && !(accumulator[0] == '\0') && !bin2c_filemanager_is_root_directory(accumulator) )\n");
410+
fprintf(fout, " if ( file_path[i] == PATH_SEPARATOR_CHAR && !(accumulator[0] == '\\0') && !bin2c_filemanager_is_root_directory(accumulator) )\n");
411411
fprintf(fout, " {\n");
412412
fprintf(fout, " int ret = portable_mkdir(accumulator);\n");
413413
fprintf(fout, " if ( ret != 0 && errno != EEXIST )\n");
@@ -418,7 +418,7 @@ namespace bin2cpp
418418
fprintf(fout, " }\n");
419419
fprintf(fout, " \n");
420420
fprintf(fout, " // append\n");
421-
fprintf(fout, " char tmp[] = { file_path[i], '\0' };\n");
421+
fprintf(fout, " char tmp[] = { file_path[i], '\\0' };\n");
422422
fprintf(fout, " strcat(accumulator, tmp);\n");
423423
fprintf(fout, " }\n");
424424
fprintf(fout, " free(accumulator);\n");
@@ -432,7 +432,7 @@ namespace bin2cpp
432432
fprintf(fout, " char* path = (char*)malloc(BIN2C_MAX_PATH);\n");
433433
fprintf(fout, " if ( path == NULL )\n");
434434
fprintf(fout, " return false;\n");
435-
fprintf(fout, " path[0] = '\0';\n");
435+
fprintf(fout, " path[0] = '\\0';\n");
436436
fprintf(fout, " for(size_t i=0; i< registered_files_count; i++)\n");
437437
fprintf(fout, " {\n");
438438
fprintf(fout, " const Bin2cFile* f = bin2c_filemanager_get_file(i);\n");

0 commit comments

Comments
 (0)