From 45f8b86f13bd5f1561d9f122bf6c3b01790407de Mon Sep 17 00:00:00 2001 From: Linus Dierheimer Date: Tue, 1 Nov 2022 14:54:27 +0100 Subject: [PATCH] Don't segfault if 0 is given as argument index #326 --- src/common/format.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/common/format.c b/src/common/format.c index 136b053d2..70f24e38e 100644 --- a/src/common/format.c +++ b/src/common/format.c @@ -38,6 +38,14 @@ void ffFormatAppendFormatArg(FFstrbuf* buffer, const FFformatarg* formatarg) } } +/** + * @brief parses a string to a uint32_t + * + * If the string can't be parsed, or is < 1, uint32_t max is returned. + * + * @param placeholderValue the string to parse + * @return uint32_t the parsed value + */ static inline uint32_t getArgumentIndex(const FFstrbuf* placeholderValue) { uint32_t result = UINT32_MAX; @@ -45,7 +53,7 @@ static inline uint32_t getArgumentIndex(const FFstrbuf* placeholderValue) if(placeholderValue->chars[0] != '-') sscanf(placeholderValue->chars, "%u", &result); - return result; + return result == 0 ? UINT32_MAX : result; } static inline void appendInvalidPlaceholder(FFstrbuf* buffer, const char* start, const FFstrbuf* placeholderValue, uint32_t index, uint32_t formatStringLength)