MCPcopy Create free account
hub / github.com/emscripten-core/emscripten / main

Function main

test/bzip2_test.c:73–140  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

71}
72
73int main ( int argc, char** argv )
74{
75 FILE* f;
76 int r;
77 int bit;
78 int i;
79
80 if (argc != 2) {
81 fprintf ( stdout, "usage: unzcrash filename\n" );
82 return 0;
83 }
84
85 f = fopen ( argv[1], "r" );
86 if (!f) {
87 fprintf ( stderr, "unzcrash: can't open %s\n", argv[1] );
88 return 1;
89 }
90
91 nIn = fread ( inbuf, 1, M_BLOCK, f );
92 fprintf ( stderr, "%d bytes read\n", nIn );
93
94 nZ = M_BLOCK;
95 r = BZ2_bzBuffToBuffCompress (
96 zbuf, &nZ, inbuf, nIn, 9, 0, 30 );
97
98 assert (r == BZ_OK);
99 fprintf ( stderr, "%d after compression\n", nZ );
100
101 for (bit = 0; bit < nZ*8; bit++) {
102 fprintf ( stderr, "bit %d ", bit );
103 flip_bit ( bit );
104 nOut = M_BLOCK_OUT;
105 r = BZ2_bzBuffToBuffDecompress (
106 outbuf, &nOut, zbuf, nZ, 0, 0 );
107 fprintf ( stderr, " %d %s ", r, bzerrorstrings[-r] );
108
109 if (r != BZ_OK) {
110 fprintf ( stderr, "\n" );
111 } else {
112 if (nOut != nIn) {
113 fprintf(stderr, "nIn/nOut mismatch %d %d\n", nIn, nOut );
114 return 1;
115 } else {
116 for (i = 0; i < nOut; i++)
117 if (inbuf[i] != outbuf[i]) {
118 fprintf(stderr, "mismatch at %d\n", i );
119 return 1;
120 }
121 if (i == nOut) fprintf(stderr, "really ok!\n" );
122 }
123 }
124
125 flip_bit ( bit );
126 }
127
128#if 0
129 assert (nOut == nIn);
130 for (i = 0; i < nOut; i++) {

Callers

nothing calls this directly

Calls 5

fprintfFunction · 0.85
fopenFunction · 0.85
freadFunction · 0.85
flip_bitFunction · 0.85
assertFunction · 0.50

Tested by

no test coverage detected