Skip to content

Commit 9c7c3fa

Browse files
CopilotNikoroCopilot
authored
Replace magic number with named constant in format_time bounds check (#30)
* Initial plan * Replace magic number with MAX_REPLACEMENT_LENGTH constant Co-authored-by: Nikoro <12560977+Nikoro@users.noreply.github.com> * Complete feedback implementation Co-authored-by: Nikoro <12560977+Nikoro@users.noreply.github.com> * Update linux/system_date_time_format_plugin.cc Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Nikoro <12560977+Nikoro@users.noreply.github.com> Co-authored-by: Dominik Krajcer <dom.kraj@gmail.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 8c3c9c6 commit 9c7c3fa

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

_codeql_detected_source_root

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.

linux/system_date_time_format_plugin.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,10 @@ char* format_time(const char* time) {
9191
char* formatted_time = (char*)malloc(BUFFER_LENGTH);
9292
if (!formatted_time) return nullptr;
9393

94+
const int MAX_REPLACEMENT_LENGTH = 10; // "hh:mm:ss a" is the longest
9495
int pos = 0;
9596
int i = 0;
96-
while (time[i] != '\0' && pos < BUFFER_LENGTH - 15) {
97+
while (time[i] != '\0' && pos < BUFFER_LENGTH - MAX_REPLACEMENT_LENGTH) {
9798
if (time[i] == '%' && time[i + 1] != '\0') {
9899
char specifier = time[i + 1];
99100
const char* replacement = nullptr;

0 commit comments

Comments
 (0)