Fix compilation when checkpoints are enabled.

- Include string.h in checkpoint.h
- Check return values of fgets calls in checkpoint.h.
- Replace variable length array in image.c by a dynamically allocated
  array.
- Add -DCHECKPOINTS to CFLAGS in Makefile when CHECKPOINTS is defined.
This commit is contained in:
Arttu Ylä-Outinen 2015-07-03 11:10:27 +03:00
parent 6eb89a2813
commit 581f740c59
3 changed files with 10 additions and 4 deletions

View file

@ -104,6 +104,10 @@ ifndef KVZ_DISABLE_ASM
endif
endif
ifdef CHECKPOINTS
CFLAGS += -DCHECKPOINTS
endif
# Compile files in strategy directories with appropriate flags.
ifeq ($(ARCH), ppc64)
strategies/altivec/%.o: EXTRA_FLAGS += -maltivec -fno-lto

View file

@ -24,6 +24,7 @@
#ifdef NDEBUG
#error "CHECKPOINTS require assertions to be enabled!"
#endif
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
@ -66,7 +67,7 @@ extern int g_ckpt_record; //Do we record?
g_ckpt_enabled = 0; \
while (!feof(g_ckpt_file)) { \
char buffer_file[4096]; \
fgets(buffer_file, 4095, g_ckpt_file); \
assert(fgets(buffer_file, 4095, g_ckpt_file) != NULL); \
if (strncmp(buffer_file, buffer_ckpt, 4096)==0) { \
g_ckpt_enabled = 1; \
break; \
@ -82,7 +83,7 @@ extern int g_ckpt_record; //Do we record?
fprintf(g_ckpt_file, str "\n", __VA_ARGS__); \
} else if (g_ckpt_enabled) { \
char buffer_file[4096], buffer_ckpt[4096]; \
fgets(buffer_file, 4095, g_ckpt_file); \
assert(fgets(buffer_file, 4095, g_ckpt_file) != NULL); \
snprintf(buffer_ckpt, 4095, str "\n", __VA_ARGS__); \
if (strncmp(buffer_file, buffer_ckpt, 4096)!=0) { \
fprintf(stderr, "Checkpoint failed (at %ld):\nFile: %sExec: %s", ftell(g_ckpt_file), buffer_file, buffer_ckpt); \

View file

@ -477,8 +477,8 @@ void pixels_blit(const kvz_pixel * const orig, kvz_pixel * const dst,
assert(width <= dst_stride);
#ifdef CHECKPOINTS
char *buffer = malloc((3 * width + 1) * sizeof(char));
for (y = 0; y < height; ++y) {
char buffer[3*width];
int p;
for (p = 0; p < width; ++p) {
sprintf((buffer + 3*p), "%02X ", orig[y*orig_stride]);
@ -486,6 +486,7 @@ void pixels_blit(const kvz_pixel * const orig, kvz_pixel * const dst,
buffer[3*width] = 0;
CHECKPOINT("pixels_blit: %04d: %s", y, buffer);
}
FREE_POINTER(buffer);
#endif //CHECKPOINTS
if (orig == dst) {