Skip to content

Commit 6c8a1d9

Browse files
hummeltechǝɹʇʇɐʃǝ◖ xıʃǝɟ
authored andcommitted
Fix numerous flawfinder issues in src/gen_tile_test.cpp
1 parent 235d530 commit 6c8a1d9

1 file changed

Lines changed: 32 additions & 33 deletions

File tree

src/gen_tile_test.cpp

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -142,33 +142,34 @@ TEST_CASE("render_expired", "render expired")
142142
{
143143

144144
SECTION("render_expired startup --help", "should start and show help message") {
145+
// flawfinder: ignore
145146
int ret = system("./render_expired -h");
146147
ret = WEXITSTATUS(ret);
147-
//CAPTURE( ret );
148148
REQUIRE(ret == 0);
149149
}
150150

151151
SECTION("render_expired startup --version", "should start and show version number") {
152+
// flawfinder: ignore
152153
FILE *pipe = popen("./render_expired -V", "r");
153154
std::string output;
154-
char buffer[strlen(VERSION) + 1];
155+
char buffer[sizeof(VERSION)];
155156
fgets(buffer, sizeof(buffer), pipe);
156157
output += buffer;
157158
pclose(pipe);
158159
REQUIRE(output == VERSION);
159160
}
160161

161162
SECTION("render_expired startup unrecognized option", "should return 1") {
163+
// flawfinder: ignore
162164
int ret = system("./render_expired --doesnotexit");
163165
ret = WEXITSTATUS(ret);
164-
//CAPTURE( ret );
165166
REQUIRE(ret == 1);
166167
}
167168

168169
SECTION("render_expired startup invalid option", "should return 1") {
170+
// flawfinder: ignore
169171
int ret = system("./render_expired -oesnotexit");
170172
ret = WEXITSTATUS(ret);
171-
//CAPTURE( ret );
172173
REQUIRE(ret == 1);
173174
}
174175
}
@@ -177,33 +178,34 @@ TEST_CASE("render_list", "render list")
177178
{
178179

179180
SECTION("render_list startup --help", "should start and show help message") {
181+
// flawfinder: ignore
180182
int ret = system("./render_list -h");
181183
ret = WEXITSTATUS(ret);
182-
//CAPTURE( ret );
183184
REQUIRE(ret == 0);
184185
}
185186

186187
SECTION("render_list startup --version", "should start and show version number") {
188+
// flawfinder: ignore
187189
FILE *pipe = popen("./render_list -V", "r");
188190
std::string output;
189-
char buffer[strlen(VERSION) + 1];
191+
char buffer[sizeof(VERSION)];
190192
fgets(buffer, sizeof(buffer), pipe);
191193
output += buffer;
192194
pclose(pipe);
193195
REQUIRE(output == VERSION);
194196
}
195197

196198
SECTION("render_list startup unrecognized option", "should return 1") {
199+
// flawfinder: ignore
197200
int ret = system("./render_list --doesnotexit");
198201
ret = WEXITSTATUS(ret);
199-
//CAPTURE( ret );
200202
REQUIRE(ret == 1);
201203
}
202204

203205
SECTION("render_list startup invalid option", "should return 1") {
206+
// flawfinder: ignore
204207
int ret = system("./render_list -doesnotexit");
205208
ret = WEXITSTATUS(ret);
206-
//CAPTURE( ret );
207209
REQUIRE(ret == 1);
208210
}
209211
}
@@ -212,33 +214,34 @@ TEST_CASE("render_old", "render old")
212214
{
213215

214216
SECTION("render_old startup --help", "should start and show help message") {
217+
// flawfinder: ignore
215218
int ret = system("./render_old -h");
216219
ret = WEXITSTATUS(ret);
217-
//CAPTURE( ret );
218220
REQUIRE(ret == 0);
219221
}
220222

221223
SECTION("render_old startup --version", "should start and show version number") {
224+
// flawfinder: ignore
222225
FILE *pipe = popen("./render_old -V", "r");
223226
std::string output;
224-
char buffer[strlen(VERSION) + 1];
227+
char buffer[sizeof(VERSION)];
225228
fgets(buffer, sizeof(buffer), pipe);
226229
output += buffer;
227230
pclose(pipe);
228231
REQUIRE(output == VERSION);
229232
}
230233

231234
SECTION("render_old startup unrecognized option", "should return 1") {
235+
// flawfinder: ignore
232236
int ret = system("./render_old --doesnotexit");
233237
ret = WEXITSTATUS(ret);
234-
//CAPTURE( ret );
235238
REQUIRE(ret == 1);
236239
}
237240

238241
SECTION("render_old startup invalid option", "should return 1") {
242+
// flawfinder: ignore
239243
int ret = system("./render_old -doesnotexit");
240244
ret = WEXITSTATUS(ret);
241-
//CAPTURE( ret );
242245
REQUIRE(ret == 1);
243246
}
244247
}
@@ -247,33 +250,34 @@ TEST_CASE("render_speedtest", "render speed test")
247250
{
248251

249252
SECTION("render_speedtest startup --help", "should start and show help message") {
253+
// flawfinder: ignore
250254
int ret = system("./render_speedtest -h");
251255
ret = WEXITSTATUS(ret);
252-
//CAPTURE( ret );
253256
REQUIRE(ret == 0);
254257
}
255258

256259
SECTION("render_speedtest startup --version", "should start and show version number") {
260+
// flawfinder: ignore
257261
FILE *pipe = popen("./render_speedtest -V", "r");
258262
std::string output;
259-
char buffer[strlen(VERSION) + 1];
263+
char buffer[sizeof(VERSION)];
260264
fgets(buffer, sizeof(buffer), pipe);
261265
output += buffer;
262266
pclose(pipe);
263267
REQUIRE(output == VERSION);
264268
}
265269

266270
SECTION("render_speedtest startup unrecognized option", "should return 1") {
271+
// flawfinder: ignore
267272
int ret = system("./render_speedtest --doesnotexit");
268273
ret = WEXITSTATUS(ret);
269-
//CAPTURE( ret );
270274
REQUIRE(ret == 1);
271275
}
272276

273277
SECTION("render_speedtest startup invalid option", "should return 1") {
278+
// flawfinder: ignore
274279
int ret = system("./render_speedtest -doesnotexit");
275280
ret = WEXITSTATUS(ret);
276-
//CAPTURE( ret );
277281
REQUIRE(ret == 1);
278282
}
279283
}
@@ -736,40 +740,41 @@ TEST_CASE("renderd", "tile generation")
736740
}
737741

738742
SECTION("renderd startup --help", "should start and show help message") {
743+
// flawfinder: ignore
739744
int ret = system("./renderd -h");
740745
ret = WEXITSTATUS(ret);
741-
//CAPTURE( ret );
742746
REQUIRE(ret == 0);
743747
}
744748

745749
SECTION("renderd startup --version", "should start and show version number") {
750+
// flawfinder: ignore
746751
FILE *pipe = popen("./renderd -V", "r");
747752
std::string output;
748-
char buffer[strlen(VERSION) + 1];
753+
char buffer[sizeof(VERSION)];
749754
fgets(buffer, sizeof(buffer), pipe);
750755
output += buffer;
751756
pclose(pipe);
752757
REQUIRE(output == VERSION);
753758
}
754759

755760
SECTION("renderd startup --config fakefile.conf --foreground", "should not start and return 1") {
761+
// flawfinder: ignore
756762
int ret = system("./renderd -c fakefile.conf -f");
757763
ret = WEXITSTATUS(ret);
758-
//CAPTURE( ret );
759764
REQUIRE(ret == 1);
760765
}
761766

762767
SECTION("renderd startup unrecognized option", "should return 1") {
768+
// flawfinder: ignore
763769
int ret = system("./renderd --doesnotexit");
764770
ret = WEXITSTATUS(ret);
765-
//CAPTURE( ret );
766771
REQUIRE(ret == 1);
767772
}
768773

769774
SECTION("renderd startup invalid option", "should return 1") {
775+
// flawfinder: ignore
770776
int ret = system("./renderd -doesnotexit");
771777
ret = WEXITSTATUS(ret);
772-
//CAPTURE( ret );
773778
REQUIRE(ret == 1);
774779
}
775780
}
@@ -909,7 +914,7 @@ TEST_CASE("storage-backend", "Tile storage backend")
909914

910915
for (int yy = 0; yy < METATILE; yy++) {
911916
for (int xx = 0; xx < METATILE; xx++) {
912-
sprintf(buf, "DEADBEAF %i %i", xx, yy);
917+
snprintf(buf, 8196, "DEADBEAF %i %i", xx, yy);
913918
std::string tile_data(buf);
914919
tiles.set(xx, yy, tile_data);
915920
}
@@ -922,7 +927,7 @@ TEST_CASE("storage-backend", "Tile storage backend")
922927
for (int xx = 0; xx < METATILE; xx++) {
923928
tile_size = store->tile_read(store, "default", "", 1024 + METATILE + xx, 1024 + yy, 10, buf, 8195, &compressed, msg);
924929
REQUIRE(tile_size == 12);
925-
sprintf(buf_tmp, "DEADBEAF %i %i", xx, yy);
930+
snprintf(buf_tmp, 8196, "DEADBEAF %i %i", xx, yy);
926931
REQUIRE(memcmp(buf_tmp, buf, 11) == 0);
927932
}
928933
}
@@ -955,7 +960,7 @@ TEST_CASE("storage-backend", "Tile storage backend")
955960

956961
for (int yy = 0; yy < METATILE; yy++) {
957962
for (int xx = 0; xx < (METATILE >> 1); xx++) {
958-
sprintf(buf, "DEADBEAF %i %i", xx, yy);
963+
snprintf(buf, 8196, "DEADBEAF %i %i", xx, yy);
959964
std::string tile_data(buf);
960965
tiles.set(xx, yy, tile_data);
961966
}
@@ -972,7 +977,7 @@ TEST_CASE("storage-backend", "Tile storage backend")
972977
REQUIRE(tile_size == 0);
973978
} else {
974979
REQUIRE(tile_size == 12);
975-
sprintf(buf_tmp, "DEADBEAF %i %i", xx, yy);
980+
snprintf(buf_tmp, 8196, "DEADBEAF %i %i", xx, yy);
976981
REQUIRE(memcmp(buf_tmp, buf, 11) == 0);
977982
}
978983
}
@@ -987,10 +992,8 @@ TEST_CASE("storage-backend", "Tile storage backend")
987992
struct storage_backend * store = NULL;
988993
struct stat_info sinfo;
989994
char * buf;
990-
char * buf_tmp;
991995

992996
buf = (char *)malloc(8196);
993-
buf_tmp = (char *)malloc(8196);
994997

995998
store = init_storage_backend(tile_dir);
996999
REQUIRE(store != NULL);
@@ -999,7 +1002,7 @@ TEST_CASE("storage-backend", "Tile storage backend")
9991002

10001003
for (int yy = 0; yy < METATILE; yy++) {
10011004
for (int xx = 0; xx < METATILE; xx++) {
1002-
sprintf(buf, "DEADBEAF %i %i", xx, yy);
1005+
snprintf(buf, 8196, "DEADBEAF %i %i", xx, yy);
10031006
std::string tile_data(buf);
10041007
tiles.set(xx, yy, tile_data);
10051008
}
@@ -1018,18 +1021,15 @@ TEST_CASE("storage-backend", "Tile storage backend")
10181021
REQUIRE(sinfo.size < 0);
10191022

10201023
free(buf);
1021-
free(buf_tmp);
10221024
store->close_storage(store);
10231025
}
10241026

10251027
SECTION("storage/expire/expiremetatile", "should expire the tile") {
10261028
struct storage_backend * store = NULL;
10271029
struct stat_info sinfo;
10281030
char * buf;
1029-
char * buf_tmp;
10301031

10311032
buf = (char *)malloc(8196);
1032-
buf_tmp = (char *)malloc(8196);
10331033

10341034
store = init_storage_backend(tile_dir);
10351035
REQUIRE(store != NULL);
@@ -1038,7 +1038,7 @@ TEST_CASE("storage-backend", "Tile storage backend")
10381038

10391039
for (int yy = 0; yy < METATILE; yy++) {
10401040
for (int xx = 0; xx < METATILE; xx++) {
1041-
sprintf(buf, "DEADBEAF %i %i", xx, yy);
1041+
snprintf(buf, 8196, "DEADBEAF %i %i", xx, yy);
10421042
std::string tile_data(buf);
10431043
tiles.set(xx, yy, tile_data);
10441044
}
@@ -1058,7 +1058,6 @@ TEST_CASE("storage-backend", "Tile storage backend")
10581058
REQUIRE(sinfo.expired > 0);
10591059

10601060
free(buf);
1061-
free(buf_tmp);
10621061
store->close_storage(store);
10631062
}
10641063

0 commit comments

Comments
 (0)