Browse Source

Enable -pedantic for the whole codebase

rexim 2 years ago
parent
commit
8c994b4535
5 changed files with 50 additions and 48 deletions
  1. 2 2
      build.sh
  2. 2 2
      demos/vc.c
  3. 39 40
      olive.c
  4. 4 3
      png2c.c
  5. 3 1
      test.c

+ 2 - 2
build.sh

@@ -2,7 +2,7 @@
 
 set -xe
 
-COMMON_CFLAGS="-Wall -Wextra -ggdb -I. -I./build/ -I./thirdparty/"
+COMMON_CFLAGS="-Wall -Wextra -pedantic -std=c99 -ggdb -I. -I./build/ -I./thirdparty/"
 
 build_wasm_demo() {
     NAME=$1
@@ -12,7 +12,7 @@ build_wasm_demo() {
 
 build_term_demo() {
     NAME=$1
-    clang $COMMON_CFLAGS -O2 -o ./build/demos/$NAME.term -DPLATFORM=TERM_PLATFORM ./demos/$NAME.c -lm
+    clang $COMMON_CFLAGS -O2 -o ./build/demos/$NAME.term -DPLATFORM=TERM_PLATFORM -D_XOPEN_SOURCE=600 ./demos/$NAME.c -lm
 }
 
 build_sdl_demo() {

+ 2 - 2
demos/vc.c

@@ -105,7 +105,7 @@ int main(void)
             for (size_t y = 0; y < actual_height; ++y) {
                 // TODO: it would be cool if Olivec_Canvas supported pitch in bytes instead of pixels
                 // It would be more flexible
-                memcpy(pixels_dst + y*pitch, oc_src.pixels + y*actual_width, actual_width*sizeof(uint32_t));
+                memcpy((char*)pixels_dst + y*pitch, oc_src.pixels + y*actual_width, actual_width*sizeof(uint32_t));
             }
             SDL_UnlockTexture(texture);
 
@@ -211,7 +211,7 @@ void compress_pixels(Olivec_Canvas oc)
 
     for (size_t y = 0; y < scaled_down_height; ++y) {
         for (size_t x = 0; x < scaled_down_width; ++x) {
-            Olivec_Canvas soc = olivec_subcanvas(oc, x*SCALE_DOWN_FACTOR, y*SCALE_DOWN_FACTOR, SCALE_DOWN_FACTOR, 
+            Olivec_Canvas soc = olivec_subcanvas(oc, x*SCALE_DOWN_FACTOR, y*SCALE_DOWN_FACTOR, SCALE_DOWN_FACTOR,
 SCALE_DOWN_FACTOR);
             char_canvas[y*scaled_down_width + x] = color_to_char(compress_pixels_chunk(soc));
         }

+ 39 - 40
olive.c

@@ -74,7 +74,7 @@ static char default_font_glyphs[128][DEFAULT_FONT_HEIGHT][DEFAULT_FONT_WIDTH] =
         {0, 1, 0, 0, 0},
         {0, 1, 0, 0, 0},
     },
-    ['g'] = {},
+    ['g'] = {0},
     ['h'] = {
         {1, 0, 0, 0, 0},
         {1, 1, 1, 0, 0},
@@ -91,8 +91,7 @@ static char default_font_glyphs[128][DEFAULT_FONT_HEIGHT][DEFAULT_FONT_WIDTH] =
         {0, 0, 1, 0, 0},
         {0, 0, 1, 0, 0},
     },
-    // TODO: this is -Wgnu-empty-initializer, get rid of all extensions with -pedantic
-    ['j'] = {},
+    ['j'] = {0},
     ['k'] = {
         {0, 1, 0, 0, 0},
         {0, 1, 0, 0, 0},
@@ -109,8 +108,8 @@ static char default_font_glyphs[128][DEFAULT_FONT_HEIGHT][DEFAULT_FONT_WIDTH] =
         {0, 0, 1, 0, 0},
         {0, 1, 1, 1, 0},
     },
-    ['m'] = {},
-    ['n'] = {},
+    ['m'] = {0},
+    ['n'] = {0},
     ['o'] = {
         {0, 0, 0, 0, 0},
         {0, 1, 1, 0, 0},
@@ -127,7 +126,7 @@ static char default_font_glyphs[128][DEFAULT_FONT_HEIGHT][DEFAULT_FONT_WIDTH] =
         {1, 0, 0, 0, 0},
         {1, 0, 0, 0, 0},
     },
-    ['q'] = {},
+    ['q'] = {0},
     ['r'] = {
         {0, 0, 0, 0, 0},
         {1, 0, 1, 1, 0},
@@ -136,10 +135,10 @@ static char default_font_glyphs[128][DEFAULT_FONT_HEIGHT][DEFAULT_FONT_WIDTH] =
         {1, 0, 0, 0, 0},
         {1, 0, 0, 0, 0},
     },
-    ['s'] = {},
-    ['t'] = {},
-    ['u'] = {},
-    ['v'] = {},
+    ['s'] = {0},
+    ['t'] = {0},
+    ['u'] = {0},
+    ['v'] = {0},
     ['w'] = {
         {0, 0, 0, 0, 0},
         {1, 0, 0, 0, 1},
@@ -148,36 +147,36 @@ static char default_font_glyphs[128][DEFAULT_FONT_HEIGHT][DEFAULT_FONT_WIDTH] =
         {1, 0, 1, 0, 1},
         {0, 1, 1, 1, 1},
     },
-    ['x'] = {},
-    ['y'] = {},
-    ['z'] = {},
-
-    ['A'] = {},
-    ['B'] = {},
-    ['C'] = {},
-    ['D'] = {},
-    ['E'] = {},
-    ['F'] = {},
-    ['G'] = {},
-    ['H'] = {},
-    ['I'] = {},
-    ['J'] = {},
-    ['K'] = {},
-    ['L'] = {},
-    ['M'] = {},
-    ['N'] = {},
-    ['O'] = {},
-    ['P'] = {},
-    ['Q'] = {},
-    ['R'] = {},
-    ['S'] = {},
-    ['T'] = {},
-    ['U'] = {},
-    ['V'] = {},
-    ['W'] = {},
-    ['X'] = {},
-    ['Y'] = {},
-    ['Z'] = {},
+    ['x'] = {0},
+    ['y'] = {0},
+    ['z'] = {0},
+
+    ['A'] = {0},
+    ['B'] = {0},
+    ['C'] = {0},
+    ['D'] = {0},
+    ['E'] = {0},
+    ['F'] = {0},
+    ['G'] = {0},
+    ['H'] = {0},
+    ['I'] = {0},
+    ['J'] = {0},
+    ['K'] = {0},
+    ['L'] = {0},
+    ['M'] = {0},
+    ['N'] = {0},
+    ['O'] = {0},
+    ['P'] = {0},
+    ['Q'] = {0},
+    ['R'] = {0},
+    ['S'] = {0},
+    ['T'] = {0},
+    ['U'] = {0},
+    ['V'] = {0},
+    ['W'] = {0},
+    ['X'] = {0},
+    ['Y'] = {0},
+    ['Z'] = {0},
 
     ['0'] = {
         {0, 1, 1, 0, 0},

+ 4 - 3
png2c.c

@@ -31,12 +31,13 @@ void usage(FILE *out, const char *program_name)
 
 void generate_c_code_from_pixels(FILE *out, uint32_t *data, int x, int y, const char *name)
 {
-    char *capital_name = strdup(name);
+    size_t name_len = strlen(name);
+    char *capital_name = malloc(name_len + 1);
     assert(capital_name != NULL && "Buy more RAM, I guess");
-    size_t name_len = strlen(capital_name);
     for (size_t i = 0; i < name_len; ++i) {
-        capital_name[i] = toupper(capital_name[i]);
+        capital_name[i] = toupper(name[i]);
     }
+    capital_name[name_len] = '\0';
 
     fprintf(out, "#ifndef %s_H_\n", capital_name);
     fprintf(out, "#define %s_H_\n", capital_name);

+ 3 - 1
test.c

@@ -8,6 +8,8 @@
 #include "./assets/tsodinPog.c"
 #include "./assets/Sadge.c"
 
+#define PI 3.14159265359
+
 #define return_defer(value) do { result = (value); goto defer; } while (0)
 #define UNUSED(x) (void)(x)
 #define UNIMPLEMENTED(message) \
@@ -348,7 +350,7 @@ Olivec_Canvas test_lines_circle(void)
     olivec_fill(oc, BACKGROUND_COLOR);
 
     size_t n = 20;
-    float angle = 2*M_PI/n;
+    float angle = 2*PI/n;
     float length = width;
     if (length > height) length = height;
     length /= 3;