Skip to content

Commit fe38404

Browse files
committed
Fix invalid strlcpy invocation.
Henceforth guarded via -Werror=strlcpy-strlcat-size where supported.
1 parent 99a0c5b commit fe38404

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,11 @@ else()
160160
target_compile_options(${PROJECT_NAME} PRIVATE -Werror=strict-prototypes)
161161
endif()
162162

163+
check_c_compiler_flag("-Wstrlcpy-strlcat-size" HAS_STRLCPY_STRLCAT_SIZE)
164+
if (HAS_STRLCPY_STRLCAT_SIZE)
165+
target_compile_options(${PROJECT_NAME} PRIVATE -Werror=strlcpy-strlcat-size)
166+
endif()
167+
163168
# Do not allow undefined symbols while linking.
164169
if(APPLE)
165170
target_link_options(${PROJECT_NAME} PRIVATE "-Wl,-undefined,error")

src/race.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3584,17 +3584,17 @@ void read_topscores(void)
35843584
race_fgets(line, MAX_TXTLEN);
35853585
race.records[cnt].time = atof(line);
35863586
race_fgets(line, MAX_TXTLEN);
3587-
strlcpy(race.records[cnt].racername, line, strlen(line));
3587+
strlcpy(race.records[cnt].racername, line, sizeof(race.records[cnt].racername));
35883588
race_fgets(line, MAX_TXTLEN);
3589-
strlcpy(race.records[cnt].demoname, line, strlen(line));
3589+
strlcpy(race.records[cnt].demoname, line, sizeof(race.records[cnt].demoname));
35903590
race_fgets(line, MAX_TXTLEN);
35913591
race.records[cnt].distance = atof(line);
35923592
race_fgets(line, MAX_TXTLEN);
35933593
race.records[cnt].maxspeed = atof(line);
35943594
race_fgets(line, MAX_TXTLEN);
35953595
race.records[cnt].avgspeed = atof(line);
35963596
race_fgets(line, MAX_TXTLEN);
3597-
strlcpy(race.records[cnt].date, line, strlen(line));
3597+
strlcpy(race.records[cnt].date, line, sizeof(race.records[cnt].date));
35983598
race_fgets(line, MAX_TXTLEN);
35993599
race.records[cnt].weaponmode = atoi(line);
36003600
race_fgets(line, MAX_TXTLEN);

0 commit comments

Comments
 (0)