diff --git a/bake.cmd b/bake.cmd index 45afddf..028e8c1 100644 --- a/bake.cmd +++ b/bake.cmd @@ -1,7 +1,7 @@ @echo off setlocal enabledelayedexpansion -set CIABATTA_OPTIONS=-Iinc -g -gcodeview -nodefaultlibs -D_CRT_SECURE_NO_WARNINGS +set CIABATTA_OPTIONS=-Iinc -Wall -g -gcodeview -nodefaultlibs -D_CRT_SECURE_NO_WARNINGS set PLATFORM=win32 if NOT "%1"=="fast" ( diff --git a/code/printf.h b/code/printf.h index 5c00884..5e68ca1 100644 --- a/code/printf.h +++ b/code/printf.h @@ -29,6 +29,7 @@ inline static int FMT_FUNC_NAME (void *ctx, OutputFunc out, const FMT_CHAR_TYPE if (isdigit(*fmt)) { // just a small atoi + // TODO: handle overflow, just in case(?) while (isdigit(*fmt)) { precision *= 10u; precision += (*fmt - '0'); diff --git a/code/stdio.c b/code/stdio.c index bc49a29..814e54c 100644 --- a/code/stdio.c +++ b/code/stdio.c @@ -2,6 +2,8 @@ #include #include +#include <_platform.h> + #define __STDC_WANT_LIB_EXT1__ 1 #include diff --git a/code/stdlib/conv.c b/code/stdlib/conv.c index 582c540..60362d8 100644 --- a/code/stdlib/conv.c +++ b/code/stdlib/conv.c @@ -20,7 +20,7 @@ typedef unsigned intu; #define inrange(start, c, end) ((start) <= (c) && (c) <= (end)) static bool isbase(int c, int base) { - int val; + int val = 0; if(isdigit(c)) { val = c-'0'; } @@ -48,7 +48,7 @@ static bool strprefix_i(char const *restrict str, char const *restrict prefix) { // Called only when isbase(c, base) for some base in range static long todigit(int c) { - int val; + int val = 0; if(isdigit(c)) { val = c-'0'; } @@ -70,6 +70,7 @@ static intull strtoi_generic(const char *restrict nptr, intull value = 0; int digits_read = 0; bool is_signed = (coefptr != NULL); + intl coef = 1; // Find max{abs(int)}. Signed integers have negative, // whose absolute value is 1 bigger than int_max. intull int_abs_max = int_max; @@ -85,7 +86,6 @@ static intull strtoi_generic(const char *restrict nptr, ++str; } // Parse sign - intl coef = 1; if(is_signed) { if(*str == '-') { coef = -1; diff --git a/code/string.c b/code/string.c index 2f4eda9..3f58a51 100644 --- a/code/string.c +++ b/code/string.c @@ -22,11 +22,9 @@ void *memcpy(void *restrict s1, const void *restrict s2, size_t n) { void *memmove(void *s1, const void *s2, size_t n) { - byte *u1 = s1; - byte const *u2 = s2; void *buffer = malloc(n); - strcpy(buffer, s2); - strcpy(s1, buffer); + memcpy(buffer, s2, n); + memcpy(s1, buffer, n); free(buffer); return s1; } @@ -90,7 +88,7 @@ int strcmp(const char *s1, const char *s2) { int strncmp(const char *s1, const char *s2, size_t n) { - int diff; + int diff = 0; size_t i = 0; if(n != 0) do { diff = *s1 - *s2; diff --git a/inc/ctype.h b/inc/ctype.h index 0d70ef7..de90aca 100644 --- a/inc/ctype.h +++ b/inc/ctype.h @@ -1,4 +1,4 @@ -#include "_platform.h" +#pragma once int isalnum(int c); int isalpha(int c); diff --git a/platform/win32/entry.c b/platform/win32/entry.c index 94896eb..500d69e 100644 --- a/platform/win32/entry.c +++ b/platform/win32/entry.c @@ -21,11 +21,10 @@ static size_t count_wide_chars(const wchar_t* str) { static bool convert_wide_chars_to_ansi(char* out, const wchar_t* str, size_t len) { for (size_t i = 0; i < len; i++) { wchar_t ch = *str++; - if (ch <= 0 && ch > 0x7F) { + if (ch < 0 || 0x7F >= ch) { *out++ = 0; return false; } - *out++ = ch; } diff --git a/platform/win32/memory.c b/platform/win32/memory.c index 746c706..0514767 100644 --- a/platform/win32/memory.c +++ b/platform/win32/memory.c @@ -39,7 +39,7 @@ void *aligned_alloc(size_t alignment, size_t size) { if(alignment > 8) { min_req_size += alignment; } - void *block_start = HeapAlloc(_heap, HEAP_ZERO_MEMORY, size+alignment); + void *block_start = HeapAlloc(_heap, HEAP_ZERO_MEMORY, min_req_size); intptr_t block_start_i = (intptr_t)block_start; intptr_t aligned_block_start_i = align_forward(block_start_i, alignment); void *aligned_block_start = (void *)aligned_block_start_i; diff --git a/test/test.c b/test/test.c index a362590..afde00a 100644 --- a/test/test.c +++ b/test/test.c @@ -8,6 +8,6 @@ int main(int argc, char** argv) { uint64_t mynumber = 4; - printf("%"PRIu64"\n", mynumber); + printf("Hello, guys %"PRIu64"\n", mynumber); return 0; } \ No newline at end of file