Skip to content

Commit 8768745

Browse files
committed
address review feedback
1 parent dd2d391 commit 8768745

1 file changed

Lines changed: 6 additions & 7 deletions

File tree

tests/ealloc_raw.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
#define HEIGHT 2
1010

1111
/* malloc failure injection */
12-
static int fail_after = 0;
13-
static int malloc_count = 0;
12+
static int fail_after;
13+
static int malloc_count;
1414

1515
static void* cgif_test_malloc(size_t size) {
1616
if(fail_after > 0) {
@@ -47,7 +47,7 @@ int main(void) {
4747
uint8_t aImageData[WIDTH * HEIGHT];
4848
memset(aImageData, 0, sizeof(aImageData));
4949

50-
for(int n = 1; ; ++n) {
50+
for(fail_after = 1; ; ++fail_after) {
5151
memset(&gConfig, 0, sizeof(gConfig));
5252
memset(&fConfig, 0, sizeof(fConfig));
5353
gConfig.pWriteFn = writeFn;
@@ -61,12 +61,11 @@ int main(void) {
6161
fConfig.height = HEIGHT;
6262
fConfig.attrFlags = CGIF_RAW_FRAME_ATTR_INTERLACED;
6363

64-
fail_after = n;
6564
malloc_count = 0;
6665

6766
pGIF = cgif_raw_newgif(&gConfig);
6867
if(pGIF == NULL) {
69-
if(malloc_count >= n) {
68+
if(malloc_count >= fail_after) {
7069
continue; // expected: our injected malloc failure
7170
}
7271
fputs("unexpected NULL from cgif_raw_newgif\n", stderr);
@@ -75,7 +74,7 @@ int main(void) {
7574

7675
r = cgif_raw_addframe(pGIF, &fConfig);
7776
if(r != CGIF_OK) {
78-
if(r == CGIF_EALLOC && malloc_count >= n) {
77+
if(r == CGIF_EALLOC && malloc_count >= fail_after) {
7978
cgif_raw_close(pGIF);
8079
continue; // expected: our injected malloc failure
8180
}
@@ -84,7 +83,7 @@ int main(void) {
8483
}
8584

8685
r = cgif_raw_close(pGIF);
87-
if(malloc_count < n) {
86+
if(malloc_count < fail_after) {
8887
// all mallocs succeeded without hitting our failure point -- done
8988
if(r != CGIF_OK) {
9089
fprintf(stderr, "unexpected error from cgif_raw_close: %d\n", r);

0 commit comments

Comments
 (0)