mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-31 05:09:12 +00:00
LibC: Fix strftime() for max_size=0
Before, strftime unintentionally interpreted 0 as 'unlimited'. The specification of strftime says no such thing. Now, it properly returns 0 in that case (because the NUL byte doesn't fit).
This commit is contained in:
parent
41b70ae8ba
commit
9785173dec
Notes:
sideshowbarker
2024-07-19 03:14:32 +09:00
Author: https://github.com/BenWiederhake
Commit: 9785173dec
Pull-request: https://github.com/SerenityOS/serenity/pull/3275
Reviewed-by: https://github.com/awesomekling
1 changed files with 4 additions and 2 deletions
|
@ -185,7 +185,7 @@ size_t strftime(char* destination, size_t max_size, const char* format, const st
|
||||||
"July", "Auguest", "September", "October", "November", "December"
|
"July", "Auguest", "September", "October", "November", "December"
|
||||||
};
|
};
|
||||||
|
|
||||||
StringBuilder builder { max_size - 1 };
|
StringBuilder builder { max_size };
|
||||||
|
|
||||||
const int format_len = strlen(format);
|
const int format_len = strlen(format);
|
||||||
for (int i = 0; i < format_len; ++i) {
|
for (int i = 0; i < format_len; ++i) {
|
||||||
|
@ -307,10 +307,12 @@ size_t strftime(char* destination, size_t max_size, const char* format, const st
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (builder.length() > max_size - 1)
|
if (builder.length() + 1 > max_size)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (builder.length() + 1 > max_size)
|
||||||
|
return 0;
|
||||||
strcpy(destination, builder.build().characters());
|
strcpy(destination, builder.build().characters());
|
||||||
return builder.length();
|
return builder.length();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue