@@ -108,38 +108,45 @@ int main(void) {
108108 malloc_count = 0 ;
109109
110110 pGIF = cgif_rgb_newgif (& gConfig );
111- if (pGIF == NULL ) {
112- if (malloc_count >= fail_after ) {
113- continue ; // expected: our injected malloc failure
111+ if (malloc_count >= fail_after ) {
112+ if (pGIF != NULL ) {
113+ fprintf (stderr , "expected NULL from cgif_rgb_newgif (fail_after=%d)\n" , fail_after );
114+ return 1 ;
114115 }
116+ continue ;
117+ }
118+ if (pGIF == NULL ) {
115119 fputs ("unexpected NULL from cgif_rgb_newgif\n" , stderr );
116120 return 1 ;
117121 }
118122
119123 r = cgif_rgb_addframe (pGIF , & fConfig );
120- if (r != CGIF_OK ) {
121- if (r == CGIF_EALLOC && malloc_count >= fail_after ) {
122- cgif_rgb_close ( pGIF );
123- continue ; // expected: our injected malloc failure
124+ if (malloc_count >= fail_after ) {
125+ if (r != CGIF_EALLOC ) {
126+ fprintf ( stderr , "expected CGIF_EALLOC from cgif_rgb_addframe, got: %d\n" , r );
127+ return 1 ;
124128 }
129+ cgif_rgb_close (pGIF );
130+ continue ;
131+ }
132+ if (r != CGIF_OK ) {
125133 fprintf (stderr , "unexpected error from cgif_rgb_addframe: %d\n" , r );
126134 return 1 ;
127135 }
128136
129137 r = cgif_rgb_close (pGIF );
130- if (malloc_count < fail_after ) {
131- // all mallocs succeeded without hitting our failure point -- done
132- if (r != CGIF_OK ) {
133- fprintf (stderr , "unexpected error from cgif_rgb_close: %d\n" , r );
138+ if (malloc_count >= fail_after ) {
139+ if (r != CGIF_EALLOC ) {
140+ fprintf (stderr , "expected CGIF_EALLOC from cgif_rgb_close, got: %d (fail_after=%d)\n" , r , fail_after );
134141 return 1 ;
135142 }
136- break ;
143+ continue ;
137144 }
138- // our injected failure was hit during close (e.g. LZW encoding)
139- if (r != CGIF_EALLOC ) {
140- fprintf (stderr , "expected CGIF_EALLOC from cgif_rgb_close, got: %d (fail_after=%d)\n" , r , fail_after );
145+ if (r != CGIF_OK ) {
146+ fprintf (stderr , "unexpected error from cgif_rgb_close: %d\n" , r );
141147 return 1 ;
142148 }
149+ break ;
143150 }
144151
145152 return 0 ;
0 commit comments