Skip to content

Commit af10797

Browse files
committed
Fix missing null terminator in strncpy_fit
1 parent d7fdefe commit af10797

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/common.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,13 @@ inline bool parse_hex_with_prefix(const std::string& hex_str, T* result)
184184

185185
inline char* strncpy_fit(char* dest, const char* src, size_t dest_size)
186186
{
187-
if (dest_size != 0)
188-
dest_size -= 1;
187+
if (dest_size == 0)
188+
return dest;
189+
190+
strncpy(dest, src, dest_size - 1);
191+
dest[dest_size - 1] = '\0';
189192

190-
return strncpy(dest, src, dest_size);
193+
return dest;
191194
}
192195

193196
inline char* strncat_fit(char* dest, const char* src, size_t dest_size)

0 commit comments

Comments
 (0)