Skip to content

Commit

Permalink
Fix invalid strlcpy invocation.
Browse files Browse the repository at this point in the history
Henceforth guarded via -Werror=strlcpy-strlcat-size where supported.
  • Loading branch information
dsvensson committed Jul 30, 2024
1 parent 99a0c5b commit fe38404
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,11 @@ else()
target_compile_options(${PROJECT_NAME} PRIVATE -Werror=strict-prototypes)
endif()

check_c_compiler_flag("-Wstrlcpy-strlcat-size" HAS_STRLCPY_STRLCAT_SIZE)
if (HAS_STRLCPY_STRLCAT_SIZE)
target_compile_options(${PROJECT_NAME} PRIVATE -Werror=strlcpy-strlcat-size)
endif()

# Do not allow undefined symbols while linking.
if(APPLE)
target_link_options(${PROJECT_NAME} PRIVATE "-Wl,-undefined,error")
Expand Down
6 changes: 3 additions & 3 deletions src/race.c
Original file line number Diff line number Diff line change
Expand Up @@ -3584,17 +3584,17 @@ void read_topscores(void)
race_fgets(line, MAX_TXTLEN);
race.records[cnt].time = atof(line);
race_fgets(line, MAX_TXTLEN);
strlcpy(race.records[cnt].racername, line, strlen(line));
strlcpy(race.records[cnt].racername, line, sizeof(race.records[cnt].racername));
race_fgets(line, MAX_TXTLEN);
strlcpy(race.records[cnt].demoname, line, strlen(line));
strlcpy(race.records[cnt].demoname, line, sizeof(race.records[cnt].demoname));
race_fgets(line, MAX_TXTLEN);
race.records[cnt].distance = atof(line);
race_fgets(line, MAX_TXTLEN);
race.records[cnt].maxspeed = atof(line);
race_fgets(line, MAX_TXTLEN);
race.records[cnt].avgspeed = atof(line);
race_fgets(line, MAX_TXTLEN);
strlcpy(race.records[cnt].date, line, strlen(line));
strlcpy(race.records[cnt].date, line, sizeof(race.records[cnt].date));
race_fgets(line, MAX_TXTLEN);
race.records[cnt].weaponmode = atoi(line);
race_fgets(line, MAX_TXTLEN);
Expand Down

0 comments on commit fe38404

Please sign in to comment.