Commit 019e874e authored by Mathis Rosenhauer's avatar Mathis Rosenhauer
Browse files

Fix clang-tidy diagnostics

parent 1553de14
...@@ -56,14 +56,33 @@ int get_param(unsigned int *param, int *iarg, char *argv[]) ...@@ -56,14 +56,33 @@ int get_param(unsigned int *param, int *iarg, char *argv[])
return 0; return 0;
} }
void usage(void)
{
fprintf(stderr, "NAME\n\taec - encode or decode files ");
fprintf(stderr, "with Adaptive Entropy Coding\n\n");
fprintf(stderr, "SYNOPSIS\n\taec [OPTION]... SOURCE DEST\n");
fprintf(stderr, "\nOPTIONS\n");
fprintf(stderr, "\t-3\n\t\t24 bit samples are stored in 3 bytes\n");
fprintf(stderr, "\t-N\n\t\tdisable pre/post processing\n");
fprintf(stderr, "\t-b size\n\t\tinternal buffer size in bytes\n");
fprintf(stderr, "\t-d\n\t\tdecode SOURCE. If -d is not used: encode.\n");
fprintf(stderr, "\t-j samples\n\t\tblock size in samples\n");
fprintf(stderr, "\t-m\n\t\tsamples are MSB first. Default is LSB\n");
fprintf(stderr, "\t-n bits\n\t\tbits per sample\n");
fprintf(stderr, "\t-p\n\t\tpad RSI to byte boundary\n");
fprintf(stderr, "\t-r blocks\n\t\treference sample interval in blocks\n");
fprintf(stderr, "\t-s\n\t\tsamples are signed. Default is unsigned\n");
fprintf(stderr, "\t-t\n\t\tuse restricted set of code options\n\n");
}
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
struct aec_stream strm; struct aec_stream strm;
unsigned char *in; unsigned char *in = NULL;
unsigned char *out; unsigned char *out = NULL;
size_t total_out; size_t total_out;
unsigned int chunk; unsigned int chunk;
int status; int status = 0;
int input_avail, output_avail; int input_avail, output_avail;
char *infn, *outfn; char *infn, *outfn;
FILE *infp, *outfp; FILE *infp, *outfp;
...@@ -81,8 +100,10 @@ int main(int argc, char *argv[]) ...@@ -81,8 +100,10 @@ int main(int argc, char *argv[])
while (iarg < argc - 2) { while (iarg < argc - 2) {
opt = argv[iarg]; opt = argv[iarg];
if (opt[0] != '-') if (opt[0] != '-') {
goto FAIL; usage();
goto DESTRUCT;
}
switch (opt[1]) { switch (opt[1]) {
case '3': case '3':
strm.flags |= AEC_DATA_3BYTE; strm.flags |= AEC_DATA_3BYTE;
...@@ -91,29 +112,37 @@ int main(int argc, char *argv[]) ...@@ -91,29 +112,37 @@ int main(int argc, char *argv[])
strm.flags &= ~AEC_DATA_PREPROCESS; strm.flags &= ~AEC_DATA_PREPROCESS;
break; break;
case 'b': case 'b':
if (get_param(&chunk, &iarg, argv)) if (get_param(&chunk, &iarg, argv)) {
goto FAIL; usage();
goto DESTRUCT;
}
break; break;
case 'd': case 'd':
dflag = 1; dflag = 1;
break; break;
case 'j': case 'j':
if (get_param(&strm.block_size, &iarg, argv)) if (get_param(&strm.block_size, &iarg, argv)) {
goto FAIL; usage();
goto DESTRUCT;
}
break; break;
case 'm': case 'm':
strm.flags |= AEC_DATA_MSB; strm.flags |= AEC_DATA_MSB;
break; break;
case 'n': case 'n':
if (get_param(&strm.bits_per_sample, &iarg, argv)) if (get_param(&strm.bits_per_sample, &iarg, argv)) {
goto FAIL; usage();
goto DESTRUCT;
}
break; break;
case 'p': case 'p':
strm.flags |= AEC_PAD_RSI; strm.flags |= AEC_PAD_RSI;
break; break;
case 'r': case 'r':
if (get_param(&strm.rsi, &iarg, argv)) if (get_param(&strm.rsi, &iarg, argv)) {
goto FAIL; usage();
goto DESTRUCT;
}
break; break;
case 's': case 's':
strm.flags |= AEC_DATA_SIGNED; strm.flags |= AEC_DATA_SIGNED;
...@@ -122,13 +151,16 @@ int main(int argc, char *argv[]) ...@@ -122,13 +151,16 @@ int main(int argc, char *argv[])
strm.flags |= AEC_RESTRICTED; strm.flags |= AEC_RESTRICTED;
break; break;
default: default:
goto FAIL; usage();
goto DESTRUCT;
} }
iarg++; iarg++;
} }
if (argc - iarg < 2) if (argc - iarg < 2) {
goto FAIL; usage();
goto DESTRUCT;
}
infn = argv[iarg]; infn = argv[iarg];
outfn = argv[iarg + 1]; outfn = argv[iarg + 1];
...@@ -145,8 +177,10 @@ int main(int argc, char *argv[]) ...@@ -145,8 +177,10 @@ int main(int argc, char *argv[])
out = (unsigned char *)malloc(chunk); out = (unsigned char *)malloc(chunk);
in = (unsigned char *)malloc(chunk); in = (unsigned char *)malloc(chunk);
if (in == NULL || out == NULL) if (in == NULL || out == NULL) {
exit(-1); status = 99;
goto DESTRUCT;
}
total_out = 0; total_out = 0;
strm.avail_in = 0; strm.avail_in = 0;
...@@ -158,11 +192,13 @@ int main(int argc, char *argv[]) ...@@ -158,11 +192,13 @@ int main(int argc, char *argv[])
if ((infp = fopen(infn, "rb")) == NULL) { if ((infp = fopen(infn, "rb")) == NULL) {
fprintf(stderr, "ERROR: cannot open input file %s\n", infn); fprintf(stderr, "ERROR: cannot open input file %s\n", infn);
return 1; status = 99;
goto DESTRUCT;
} }
if ((outfp = fopen(outfn, "wb")) == NULL) { if ((outfp = fopen(outfn, "wb")) == NULL) {
fprintf(stderr, "ERROR: cannot open output file %s\n", infn); fprintf(stderr, "ERROR: cannot open output file %s\n", infn);
return 1; status = 99;
goto DESTRUCT;
} }
if (dflag) if (dflag)
...@@ -172,7 +208,7 @@ int main(int argc, char *argv[]) ...@@ -172,7 +208,7 @@ int main(int argc, char *argv[])
if (status != AEC_OK) { if (status != AEC_OK) {
fprintf(stderr, "ERROR: initialization failed (%d)\n", status); fprintf(stderr, "ERROR: initialization failed (%d)\n", status);
return 1; goto DESTRUCT;
} }
while(input_avail || output_avail) { while(input_avail || output_avail) {
...@@ -190,7 +226,7 @@ int main(int argc, char *argv[]) ...@@ -190,7 +226,7 @@ int main(int argc, char *argv[])
if (status != AEC_OK) { if (status != AEC_OK) {
fprintf(stderr, "ERROR: %i\n", status); fprintf(stderr, "ERROR: %i\n", status);
return 1; goto DESTRUCT;
} }
if (strm.total_out - total_out > 0) { if (strm.total_out - total_out > 0) {
...@@ -210,7 +246,7 @@ int main(int argc, char *argv[]) ...@@ -210,7 +246,7 @@ int main(int argc, char *argv[])
} else { } else {
if ((status = aec_encode(&strm, AEC_FLUSH)) != AEC_OK) { if ((status = aec_encode(&strm, AEC_FLUSH)) != AEC_OK) {
fprintf(stderr, "ERROR: while flushing output (%i)\n", status); fprintf(stderr, "ERROR: while flushing output (%i)\n", status);
return 1; goto DESTRUCT;
} }
if (strm.total_out - total_out > 0) if (strm.total_out - total_out > 0)
...@@ -221,25 +257,11 @@ int main(int argc, char *argv[]) ...@@ -221,25 +257,11 @@ int main(int argc, char *argv[])
fclose(infp); fclose(infp);
fclose(outfp); fclose(outfp);
free(in);
free(out);
return 0;
FAIL: DESTRUCT:
fprintf(stderr, "NAME\n\taec - encode or decode files "); if (in)
fprintf(stderr, "with Adaptive Entropy Coding\n\n"); free(in);
fprintf(stderr, "SYNOPSIS\n\taec [OPTION]... SOURCE DEST\n"); if (out)
fprintf(stderr, "\nOPTIONS\n"); free(out);
fprintf(stderr, "\t-3\n\t\t24 bit samples are stored in 3 bytes\n"); return status;
fprintf(stderr, "\t-N\n\t\tdisable pre/post processing\n");
fprintf(stderr, "\t-b size\n\t\tinternal buffer size in bytes\n");
fprintf(stderr, "\t-d\n\t\tdecode SOURCE. If -d is not used: encode.\n");
fprintf(stderr, "\t-j samples\n\t\tblock size in samples\n");
fprintf(stderr, "\t-m\n\t\tsamples are MSB first. Default is LSB\n");
fprintf(stderr, "\t-n bits\n\t\tbits per sample\n");
fprintf(stderr, "\t-p\n\t\tpad RSI to byte boundary\n");
fprintf(stderr, "\t-r blocks\n\t\treference sample interval in blocks\n");
fprintf(stderr, "\t-s\n\t\tsamples are signed. Default is unsigned\n");
fprintf(stderr, "\t-t\n\t\tuse restricted set of code options\n\n");
return 1;
} }
...@@ -87,7 +87,8 @@ int main (void) ...@@ -87,7 +87,8 @@ int main (void)
if (!state.ubuf || !state.cbuf || !state.obuf) { if (!state.ubuf || !state.cbuf || !state.obuf) {
printf("Not enough memory.\n"); printf("Not enough memory.\n");
return 99; status = 99;
goto DESTRUCT;
} }
strm.flags = AEC_DATA_PREPROCESS; strm.flags = AEC_DATA_PREPROCESS;
...@@ -100,9 +101,12 @@ int main (void) ...@@ -100,9 +101,12 @@ int main (void)
goto DESTRUCT; goto DESTRUCT;
DESTRUCT: DESTRUCT:
free(state.ubuf); if (state.ubuf)
free(state.cbuf); free(state.ubuf);
free(state.obuf); if (state.cbuf)
free(state.cbuf);
if (state.obuf)
free(state.obuf);
return status; return status;
} }
...@@ -303,7 +303,8 @@ int main(int argc, char *argv[]) ...@@ -303,7 +303,8 @@ int main(int argc, char *argv[])
if (!state.ubuf || !state.cbuf || !state.obuf) { if (!state.ubuf || !state.cbuf || !state.obuf) {
printf("Not enough memory.\n"); printf("Not enough memory.\n");
return 99; status = 99;
goto DESTRUCT;
} }
strm.flags = 0; strm.flags = 0;
...@@ -324,9 +325,12 @@ int main(int argc, char *argv[]) ...@@ -324,9 +325,12 @@ int main(int argc, char *argv[])
status = check_byte_orderings(&state); status = check_byte_orderings(&state);
DESTRUCT: DESTRUCT:
free(state.ubuf); if (state.ubuf)
free(state.cbuf); free(state.ubuf);
free(state.obuf); if (state.cbuf)
free(state.cbuf);
if (state.obuf)
free(state.obuf);
return status; return status;
} }
...@@ -11,9 +11,11 @@ ...@@ -11,9 +11,11 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
int status; int status = 0;
SZ_com_t sz_param; SZ_com_t sz_param;
unsigned char *source, *dest, *dest1; unsigned char *source = NULL;
unsigned char *dest = NULL;
unsigned char *dest1 = NULL;
size_t destLen, dest1Len, sourceLen; size_t destLen, dest1Len, sourceLen;
FILE *fp; FILE *fp;
...@@ -40,27 +42,33 @@ int main(int argc, char *argv[]) ...@@ -40,27 +42,33 @@ int main(int argc, char *argv[])
dest = (unsigned char *)malloc(destLen); dest = (unsigned char *)malloc(destLen);
dest1 = (unsigned char *)malloc(destLen); dest1 = (unsigned char *)malloc(destLen);
if (source == NULL || dest == NULL || dest1 == NULL) if (source == NULL || dest == NULL || dest1 == NULL) {
return 1; status = 99;
goto DESTRUCT;
}
sourceLen = fread(source, 1, sourceLen, fp); sourceLen = fread(source, 1, sourceLen, fp);
status = SZ_BufftoBuffCompress(dest, &destLen, status = SZ_BufftoBuffCompress(dest, &destLen,
source, sourceLen, &sz_param); source, sourceLen, &sz_param);
if (status != SZ_OK) if (status != SZ_OK)
return status; goto DESTRUCT;
dest1Len = sourceLen; dest1Len = sourceLen;
status = SZ_BufftoBuffDecompress(dest1, &dest1Len, status = SZ_BufftoBuffDecompress(dest1, &dest1Len,
dest, destLen, &sz_param); dest, destLen, &sz_param);
if (status != SZ_OK) if (status != SZ_OK)
return status; goto DESTRUCT;
if (memcmp(source, dest1, sourceLen) != 0) if (memcmp(source, dest1, sourceLen) != 0)
fprintf(stderr, "File %s Buffers differ\n", argv[2]); fprintf(stderr, "File %s Buffers differ\n", argv[2]);
free(source); DESTRUCT:
free(dest); if (source)
free(dest1); free(source);
return 0; if (dest)
free(dest);
if (dest1)
free(dest1);
return status;
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment