X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=main.c;h=a1e4e24dd42f6d3d7f804e101a6d7363834d3b4a;hb=ef3b0164cbb6c9d616c3fdad92fb8da669e4b5d7;hp=47e85475885a5251902db6d25335b7a23ae39416;hpb=7b47e505268f20084f7253575e6b6506f371f746;p=cparser diff --git a/main.c b/main.c index 47e8547..a1e4e24 100644 --- a/main.c +++ b/main.c @@ -46,6 +46,7 @@ #include #include +#include "adt/util.h" #include "ast_t.h" #include "preprocessor.h" #include "token_t.h" @@ -359,8 +360,7 @@ static bool run_external_preprocessor(compilation_unit_t *unit) static char dep_target[4096]; if (outname != 0) { size_t len = strlen(outname); - if (len > sizeof(dep_target)-4) /* leave room for .d extension */ - len = sizeof(dep_target)-4; + len = MIN(len, sizeof(dep_target) - 4); /* leave room for .d extension */ memcpy(dep_target, outname, len); /* replace extension with .d if found */ char *dot = &dep_target[len-1]; @@ -900,9 +900,7 @@ static unsigned decide_modulo_shift(unsigned type_size) { if (architecture_modulo_shift == 0) return 0; - if (type_size < architecture_modulo_shift) - return architecture_modulo_shift; - return type_size; + return MAX(type_size, architecture_modulo_shift); } static bool is_ia32_cpu(const char *architecture) @@ -1202,8 +1200,10 @@ static void copy_file(FILE *dest, FILE *input) { char buf[16384]; - while (!feof(input) && !ferror(dest)) { + for (;;) { size_t read = fread(buf, 1, sizeof(buf), input); + if (read == 0) + break; if (fwrite(buf, 1, read, dest) != read) { perror("could not write output"); }