Check STR_SIZE_MAX in Strcat_char

This commit is contained in:
Tatsuya Kinoshita
2021-03-21 12:51:08 +09:00
parent 4da429056b
commit 15520de3aa
2 changed files with 3 additions and 3 deletions

2
Str.c
View File

@@ -21,12 +21,10 @@
#ifdef __EMX__ /* or include "fm.h" for HAVE_BCOPY? */ #ifdef __EMX__ /* or include "fm.h" for HAVE_BCOPY? */
#include <strings.h> #include <strings.h>
#endif #endif
#include <limits.h>
#include "Str.h" #include "Str.h"
#include "myctype.h" #include "myctype.h"
#define INITIAL_STR_SIZE 32 #define INITIAL_STR_SIZE 32
#define STR_SIZE_MAX (INT_MAX / 32)
#ifdef STR_DEBUG #ifdef STR_DEBUG
/* This is obsolete, because "Str" can handle a '\0' character now. */ /* This is obsolete, because "Str" can handle a '\0' character now. */

4
Str.h
View File

@@ -17,6 +17,7 @@
#define GC_STR_H #define GC_STR_H
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <limits.h>
#ifdef __EMX__ #ifdef __EMX__
#define strcasecmp stricmp #define strcasecmp stricmp
#define strncasecmp strnicmp #define strncasecmp strnicmp
@@ -66,7 +67,8 @@ Str Strfgetall(FILE *);
void Strgrow(Str s); void Strgrow(Str s);
#define Strcat_char(x,y) (((x)->length+1>=(x)->area_size)?Strgrow(x),0:0,(x)->ptr[(x)->length++]=(y),(x)->ptr[(x)->length]=0) #define STR_SIZE_MAX (INT_MAX / 32)
#define Strcat_char(x,y) (((x)->length+1>=STR_SIZE_MAX)?0:(((x)->length+1>=(x)->area_size)?Strgrow(x),0:0,(x)->ptr[(x)->length++]=(y),(x)->ptr[(x)->length]=0))
#define Strcmp(x,y) strcmp((x)->ptr,(y)->ptr) #define Strcmp(x,y) strcmp((x)->ptr,(y)->ptr)
#define Strcmp_charp(x,y) strcmp((x)->ptr,(y)) #define Strcmp_charp(x,y) strcmp((x)->ptr,(y))
#define Strncmp(x,y,n) strncmp((x)->ptr,(y)->ptr,(n)) #define Strncmp(x,y,n) strncmp((x)->ptr,(y)->ptr,(n))