Bug Summary

File:ss_grandia_comp_tool.c
Warning:line 107, column 9
Value stored to 'arg_found' is never read

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name ss_grandia_comp_tool.c -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -mrelocation-model pic -pic-level 2 -pic-is-pie -mthread-model posix -mframe-pointer=all -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -dwarf-column-info -debugger-tuning=gdb -resource-dir /usr/lib/clang/10.0.0 -I ./src -I ./src/inc -internal-isystem /usr/local/include -internal-isystem /usr/lib/clang/10.0.0/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -O0 -Wno-sign-compare -std=c11 -fdebug-compilation-dir /tmp/ssgctv09 -ferror-limit 19 -fmessage-length 0 -stack-protector 2 -fobjc-runtime=gcc -fdiagnostics-show-option -analyzer-checker alpha.core.CallAndMessageUnInitRefArg -analyzer-checker alpha.core.CastToStruct -analyzer-checker alpha.core.Conversion -analyzer-checker alpha.core.FixedAddr -analyzer-checker alpha.core.IdenticalExpr -analyzer-checker alpha.core.PointerArithm -analyzer-checker alpha.core.SizeofPtr -analyzer-checker alpha.core.TestAfterDivZero -analyzer-checker alpha.security.MallocOverflow -analyzer-checker alpha.security.ReturnPtrRange -analyzer-checker alpha.unix.BlockInCriticalSection -analyzer-checker alpha.unix.Chroot -analyzer-checker alpha.unix.PthreadLock -analyzer-checker alpha.unix.SimpleStream -analyzer-checker alpha.unix.Stream -analyzer-checker alpha.unix.cstring.BufferOverlap -analyzer-checker alpha.unix.cstring.NotNullTerminated -analyzer-checker valist.CopyToSelf -analyzer-checker valist.Uninitialized -analyzer-checker valist.Unterminated -analyzer-checker security.FloatLoopCounter -analyzer-checker security.insecureAPI.strcpy -analyzer-max-loop 1536 -analyzer-output=html -faddrsig -o /tmp/scan-build-2019-10-07-120410-3045-1 -x c src/ss_grandia_comp_tool.c
1/*
2 ============================================================================
3 Name : ss_grandia_comp_tool.c
4 Author : nanash1
5 Version : 0.9
6 Description : Tool to compress and decompress Grandia Saturn graphics
7 ============================================================================
8 */
9
10/**
11* This software is supplied "AS IS" without any warranties of
12* any kind. The author, nanash1, assumes no responsibility
13* or liability for the use of the software, conveys no license or rights under any
14* patent, copyright, mask work right, or any other intellectual property rights in
15* or to any products. The author also makes no
16* representation or warranty that such application will be suitable for the
17* specified use without further testing or modification.
18*
19* Permission to use, copy, modify, and distribute this software and its
20* documentation is hereby granted. This copyright, permission, and disclaimer
21* notice must appear in all copies of this code.
22*/
23
24#include <stdio.h>
25#include <stdint.h>
26#include <stdlib.h>
27#include <string.h>
28#include <errno(*__errno_location ()).h>
29#include "compression.h"
30
31enum mode {
32 COMPRESS,
33 DECOMPRESS
34};
35
36uint8_t lut_table[9];
37char lut_table_str[22] = {0};
38
39static void lut_to_string(void)
40{
41 lut_table_str[0] = '0';
42 lut_table_str[1] = 'x';
43 for (uint_fast8_t i = 0; i < 9; i++){
44 if (lut_table[i] < 0xf){
45 lut_table_str[2+2*i] = '0';
46 sprintf(&lut_table_str[2] + 2*i+1, "%x", lut_table[i]);
47 } else {
48 sprintf(&lut_table_str[2] + 2*i, "%x", lut_table[i]);
49 }
50 }
51}
52
53int main(int argc, char* argv[])
54{
55 compression_status_t status;
56 enum mode op_mode;
57 uint_fast8_t arg_found;
58 const char* input;
59 const char* output;
60
61 uint32_t compressed_data_offset = 0x0;
62 enum comp_mode comp_mode = SUB_MODE;
63 uint8_t rle_limit = 6;
64
65 uint8_t table_arg_ind;
66 size_t table_size;
67
68 printf("Saturn Grandia graphics compression tool version v0.9 by nanash1\n\n");
69
70 if(argc == 1){
71 printf("No arguments specified. Please refer to the readme file.\n");
72 return 0;
73 }
74
75 if(!strcmp(argv[1], "compress")){
76 op_mode = COMPRESS;
77 } else if (!strcmp(argv[1], "decompress")){
78 op_mode = DECOMPRESS;
79 } else {
80 printf("Invalid operations mode argument. Mode must be compress or decompress.\n");
81 return 0;
82 }
83
84 arg_found = 0;
85 for (uint_fast8_t i = 1; i < (argc - 1); i++){
86 if (!strcmp(argv[i], "-i")){
87 input = argv[i+1];
88 arg_found++;
89 break;
90 }
91 }
92 for (uint_fast8_t i = 1; i < (argc - 1); i++){
93 if (!strcmp(argv[i], "-o")){
94 output = argv[i+1];
95 arg_found++;
96 break;
97 }
98 }
99
100 if (arg_found != 2){
101 printf("Please specify input and output file.\n");
102 return 0;
103 }
104
105 if (op_mode == DECOMPRESS){
106
107 arg_found = 0;
Value stored to 'arg_found' is never read
108 for (uint_fast8_t i = 1; i < (argc - 1); i++){
109 if (!strcmp(argv[i], "-c")){
110 compressed_data_offset = strtol(argv[i+1], NULL((void*)0), 0);
111 break;
112 }
113 }
114
115 if (errno(*__errno_location ())){
116 printf("Error: %d.\n", errno(*__errno_location ()));
117 return 0;
118 }
119
120 status = decompress(input, output, compressed_data_offset, &comp_mode, &lut_table[0], &rle_limit);
121
122 } else if (op_mode == COMPRESS){
123
124 arg_found = 0;
125 for (uint_fast8_t i = 1; i < (argc - 1); i++){
126 if (!strcmp(argv[i], "-t")){
127
128 table_arg_ind = i + 1;
129 /* check if the table has a valid format */
130 table_size = strlen(argv[i+1]);
131 char segment[3] = {0};
132 memcpy(&segment[0], argv[i+1], 2);
133 if (strcmp(segment, "0x")){
134 printf("Table must be specified as hex value. Use the prefix 0x.\n");
135 return 0;
136 }
137 if (table_size < 20){
138 printf("Table must be at least 9 bytes long. Note that further bytes are ignored.\n");
139 return 0;
140 }
141
142 /* copy the table data to memory */
143 for (uint_fast8_t j = 0; j < 9; j++){
144 memcpy(&segment[0], &argv[i+1][2+(2*j)], 2);
145 lut_table[j] = strtol(&segment[0], NULL((void*)0), 16);
146 }
147 arg_found++;
148 break;
149 }
150 }
151
152 if (!arg_found){
153 printf("Please specify a decompression table.\n");
154 return 0;
155 }
156
157 for (uint_fast8_t i = 1; i < (argc - 1); i++){
158 if (!strcmp(argv[i], "-x")){
159 comp_mode = XOR_MODE;
160 break;
161 } else if (!strcmp(argv[i], "-s")){
162 comp_mode = SUB_MODE;
163 break;
164 } else if (!strcmp(argv[i], "-m")){
165 comp_mode = MOV_MODE;
166 break;
167 }
168 }
169
170 for (uint_fast8_t i = 1; i < (argc - 1); i++){
171 if (!strcmp(argv[i], "-z")){
172 rle_limit = (uint8_t) strtol(argv[i+1], NULL((void*)0), 0);;
173 break;
174 }
175 }
176
177 if (errno(*__errno_location ())){
178 printf("Error: %d.\n", errno(*__errno_location ()));
179 return 0;
180 }
181
182 status = compress(comp_mode, input, output, (uint8_t*) &lut_table[0], rle_limit);
183 }
184
185 /* print informations if successful */
186 if (status == SUCCESS){
187 printf("Output was written successfully.\n");
188
189 if (op_mode == DECOMPRESS){
190 lut_to_string();
191 printf("Table: %s\n", lut_table_str);
192 } else {
193 printf("Table: %s\n", argv[table_arg_ind]);
194 }
195 printf("RLE limit: %u\n", rle_limit);
196 printf("Mode: ");
197 switch (comp_mode){
198 case XOR_MODE:
199 printf("XOR\n");
200 break;
201 case MOV_MODE:
202 printf("MOV\n");
203 break;
204 case SUB_MODE:
205 printf("SUB\n");
206 break;
207 }
208 }
209
210 /* print error messages */
211 switch (status){
212 case SUCCESS:
213 break;
214 case FILE_NOT_FOUND:
215 printf("File not found.\n");
216 break;
217 case INSUFFICIENT_MEM:
218 printf("Out of memory.\n");
219 break;
220 case RUNAWAY_DATA:
221 printf("Couldn't find end of stream. Please check offsets or image data.\n");
222 break;
223 case INVALID_HEADER:
224 printf("Invalid header. Please check the offsets.\n");
225 break;
226 case INVALID_TABLE:
227 printf("Compression table invalid.\n");
228 break;
229 }
230
231 return 0;
232}