int sscanf(const char* str, const char* fmt, ...) {
/* Minimal sscanf: only supports %d and %s */
+ /* U02: %s limited to 255 chars by default to prevent buffer overflow */
va_list ap;
va_start(ap, fmt);
int count = 0;
char* out = va_arg(ap, char*);
while (*s == ' ') s++;
int i = 0;
- while (*s && *s != ' ' && *s != '\n' && *s != '\t') out[i++] = *s++;
+ while (*s && *s != ' ' && *s != '\n' && *s != '\t' && i < 255) out[i++] = *s++;
out[i] = '\0';
count++;
} else {
int fscanf(FILE* fp, const char* fmt, ...) {
/* Read a line, then delegate to sscanf */
+ /* U02: %s limited to 255 chars by default to prevent buffer overflow */
char line[512];
if (!fgets(line, (int)sizeof(line), fp)) return EOF;
va_list ap;
char* out = va_arg(ap, char*);
while (*s == ' ') s++;
int i = 0;
- while (*s && *s != ' ' && *s != '\n' && *s != '\t') out[i++] = *s++;
+ while (*s && *s != ' ' && *s != '\n' && *s != '\t' && i < 255) out[i++] = *s++;
out[i] = '\0';
count++;
} else if (*f == 'c') {
}
int scanf(const char* fmt, ...) {
+ /* U02: %s limited to 255 chars by default to prevent buffer overflow */
char line[512];
if (!fgets(line, (int)sizeof(line), stdin)) return EOF;
va_list ap;
char* out = va_arg(ap, char*);
while (*s == ' ') s++;
int i = 0;
- while (*s && *s != ' ' && *s != '\n' && *s != '\t') out[i++] = *s++;
+ while (*s && *s != ' ' && *s != '\n' && *s != '\t' && i < 255) out[i++] = *s++;
out[i] = '\0';
count++;
} else {