@@ -66,10 +66,14 @@ int main(void) {
6666 malloc_count = 0 ;
6767
6868 pGIF = cgif_newgif (& gConfig );
69- if (pGIF == NULL ) {
70- if (malloc_count >= fail_after ) {
71- continue ;
69+ if (malloc_count >= fail_after ) {
70+ if (pGIF != NULL ) {
71+ fprintf (stderr , "expected NULL from cgif_newgif (fail_after=%d)\n" , fail_after );
72+ return 1 ;
7273 }
74+ continue ;
75+ }
76+ if (pGIF == NULL ) {
7377 fputs ("unexpected NULL from cgif_newgif\n" , stderr );
7478 return 1 ;
7579 }
@@ -81,11 +85,15 @@ int main(void) {
8185 fConfig .pLocalPalette = aPalette ;
8286 fConfig .numLocalPaletteEntries = 2 ;
8387 r = cgif_addframe (pGIF , & fConfig );
84- if (r != CGIF_OK ) {
85- if (r == CGIF_EALLOC && malloc_count >= fail_after ) {
86- cgif_close ( pGIF );
87- continue ;
88+ if (malloc_count >= fail_after ) {
89+ if (r != CGIF_EALLOC ) {
90+ fprintf ( stderr , "expected CGIF_EALLOC from cgif_addframe (frame 1), got: %d\n" , r );
91+ return 1 ;
8892 }
93+ cgif_close (pGIF );
94+ continue ;
95+ }
96+ if (r != CGIF_OK ) {
8997 fprintf (stderr , "unexpected error from cgif_addframe (frame 1): %d\n" , r );
9098 return 1 ;
9199 }
@@ -95,11 +103,15 @@ int main(void) {
95103 fConfig .pImageData = aImageData1 ;
96104 fConfig .genFlags = CGIF_FRAME_GEN_USE_DIFF_WINDOW ;
97105 r = cgif_addframe (pGIF , & fConfig );
98- if (r != CGIF_OK ) {
99- if (r == CGIF_EALLOC && malloc_count >= fail_after ) {
100- cgif_close ( pGIF );
101- continue ;
106+ if (malloc_count >= fail_after ) {
107+ if (r != CGIF_EALLOC ) {
108+ fprintf ( stderr , "expected CGIF_EALLOC from cgif_addframe (frame 2), got: %d\n" , r );
109+ return 1 ;
102110 }
111+ cgif_close (pGIF );
112+ continue ;
113+ }
114+ if (r != CGIF_OK ) {
103115 fprintf (stderr , "unexpected error from cgif_addframe (frame 2): %d\n" , r );
104116 return 1 ;
105117 }
@@ -109,30 +121,32 @@ int main(void) {
109121 fConfig .pImageData = aImageData0 ;
110122 fConfig .genFlags = CGIF_FRAME_GEN_USE_TRANSPARENCY ;
111123 r = cgif_addframe (pGIF , & fConfig );
112- if (r != CGIF_OK ) {
113- if (r == CGIF_EALLOC && malloc_count >= fail_after ) {
114- cgif_close ( pGIF );
115- continue ;
124+ if (malloc_count >= fail_after ) {
125+ if (r != CGIF_EALLOC ) {
126+ fprintf ( stderr , "expected CGIF_EALLOC from cgif_addframe (frame 3), got: %d\n" , r );
127+ return 1 ;
116128 }
129+ cgif_close (pGIF );
130+ continue ;
131+ }
132+ if (r != CGIF_OK ) {
117133 fprintf (stderr , "unexpected error from cgif_addframe (frame 3): %d\n" , r );
118134 return 1 ;
119135 }
120136
121137 r = cgif_close (pGIF );
122- if (malloc_count < fail_after ) {
123- // all mallocs succeeded without hitting our failure point -- done
124- if (r != CGIF_OK ) {
125- fprintf (stderr , "unexpected error from cgif_close: %d\n" , r );
138+ if (malloc_count >= fail_after ) {
139+ if (r != CGIF_EALLOC ) {
140+ fprintf (stderr , "expected CGIF_EALLOC from cgif_close, got: %d (fail_after=%d)\n" , r , fail_after );
126141 return 1 ;
127142 }
128- break ;
143+ continue ;
129144 }
130- // our injected failure was hit during close (e.g. LZW encoding)
131- if (r != CGIF_EALLOC ) {
132- fprintf (stderr , "expected CGIF_EALLOC from cgif_close, got: %d (fail_after=%d)\n" , r , fail_after );
145+ if (r != CGIF_OK ) {
146+ fprintf (stderr , "unexpected error from cgif_close: %d\n" , r );
133147 return 1 ;
134148 }
135- continue ;
149+ break ;
136150 }
137151
138152 return 0 ;
0 commit comments