Skip to content

Commit f325267

Browse files
committed
Fix read past end of buffer in flint_fprintf
1 parent 9cf621c commit f325267

File tree

1 file changed

+3
-3
lines changed
  • src/generic_files

1 file changed

+3
-3
lines changed

src/generic_files/io.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include <ctype.h> /* isdigit */
1313
#include <stdint.h> /* intmax_t */
1414
#include <stdio.h>
15-
#include <string.h> /* memcpy, memcmp and strchr */
15+
#include <string.h> /* memcpy, strncmp and strchr */
1616
#include <stdarg.h>
1717
#include <wchar.h> /* wchar_t and wint_t */
1818
#include "nmod_types.h"
@@ -203,8 +203,8 @@ static size_t __flint_poly_fprint(FILE *, const void *, flint_type_t);
203203

204204
/* TODO: Add options for compact/spacious printing. */
205205

206-
#define IS_FLINT_BASE_TYPE(ip, str) (memcmp(ip, str, sizeof(str) - sizeof(char)) == 0)
207-
#define IS_FLINT_TYPE(ip, str) (memcmp(ip, str "}", sizeof(str)) == 0)
206+
#define IS_FLINT_BASE_TYPE(ip, str) (strncmp(ip, str, STRING_LENGTH(str)) == 0)
207+
#define IS_FLINT_TYPE(ip, str) (strncmp(ip, str "}", STRING_LENGTH(str) + 1) == 0)
208208

209209
/* Reference used for checks: https://en.cppreference.com/w/c/io/fprintf */
210210
#define IS_PRINTF_FLAG(chr) \

0 commit comments

Comments
 (0)