Parcourir la source

Enable many warning flags and fix the problems discovered by them

rexim il y a 4 ans
Parent
commit
1f635227e0
6 fichiers modifiés avec 15 ajouts et 8 suppressions
  1. 1 1
      examples/file.c
  2. 1 1
      examples/foreach.c
  3. 1 1
      examples/logging.c
  4. 1 1
      examples/string.c
  5. 6 1
      nobuild.c
  6. 5 3
      nobuild.h

+ 1 - 1
examples/file.c

@@ -18,7 +18,7 @@ void print_file_recursively(const char *path)
     }
 }
 
-int main(int argc, char *argv[])
+int main(void)
 {
     DEMO(IS_DIR("./nobuild.c"));
     DEMO(IS_DIR("./examples"));

+ 1 - 1
examples/foreach.c

@@ -34,7 +34,7 @@ void foreach_file_in_dir(const char *dir_path)
         expr;                                   \
     } while(0)
 
-int main(int argc, char *argv[])
+int main(void)
 {
     DEMO(foreach_vargs(69, "foo", "bar", "baz", NULL));
     DEMO(foreach_array());

+ 1 - 1
examples/logging.c

@@ -1,7 +1,7 @@
 #define NOBUILD_IMPLEMENTATION
 #include "../nobuild.h"
 
-int main(int argc, char *argv[])
+int main(void)
 {
     INFO("    Informational Message");
     WARN("    Warning Message");

+ 1 - 1
examples/string.c

@@ -7,7 +7,7 @@
 #define DEMO_D(expr)                         \
     INFO("    " #expr " == %d", expr)
 
-int main(int argc, char *argv[])
+int main(void)
 {
     DEMO_S(CONCAT("foo", "bar", "baz"));
     DEMO_S(PATH("foo", "bar", "baz"));

+ 6 - 1
nobuild.c

@@ -1,6 +1,8 @@
 #define NOBUILD_IMPLEMENTATION
 #include "./nobuild.h"
 
+#define CFLAGS "-Wall", "-Wextra", "-std=c11"//, "-pedantic"
+
 void check_example(const char *example)
 {
     const char *example_path = PATH("examples", NOEXT(example));
@@ -11,7 +13,10 @@ void check_example(const char *example)
     CMD("cl.exe", "/Fe.\\examples\\", PATH("examples", example));
     CMD(CONCAT(example_path, ".exe"));
 #else
-    CMD("cc", "-o", example_path, PATH("examples", example));
+    const char *cc = getenv("CC");
+    if (cc == NULL) cc = "cc";
+
+    CMD(cc, CFLAGS, "-o", example_path, PATH("examples", example));
     CMD(example_path);
 #endif // _WIN32
 }

+ 5 - 3
nobuild.h

@@ -553,6 +553,8 @@ const char *remove_ext(const char *path)
 {
     WARN("DEPRECATED: Please use `NOEXT(path)` instead of `remove_ext(path)`. `remove_ext(path)` will be removed in the next major release.");
     nobuild__remove_ext(path);
+
+    return NULL;
 }
 
 char *shift(int *argc, char ***argv)
@@ -629,7 +631,7 @@ int nobuild__is_dir(const char *path)
         exit(1);
     }
 
-    return (statbuf.st_mode & S_IFMT) == S_IFDIR;
+    return S_ISDIR(statbuf.st_mode);
 #endif // _WIN32
 }
 
@@ -643,7 +645,7 @@ void nobuild__rm(const char *path)
         });
 
         if (rmdir(path) < 0) {
-            if (errno = ENOENT) {
+            if (errno == ENOENT) {
                 WARN("directory %s does not exist");
             } else {
                 ERRO("could not remove directory %s: %s", path, strerror(errno));
@@ -652,7 +654,7 @@ void nobuild__rm(const char *path)
         }
     } else {
         if (unlink(path) < 0) {
-            if (errno = ENOENT) {
+            if (errno == ENOENT) {
                 WARN("file %s does not exist");
             } else {
                 ERRO("could not remove file %s: %s", path, strerror(errno));