mirror of
https://github.com/DarkPlacesEngine/gmqcc.git
synced 2025-02-21 02:40:56 +00:00
flatten the use of strcpy, 90% of the cases we already knew the length of the string either at compile-time, or already within the scope we where, thus letting us use strncpy, which can be further optimized (unrolled if static)
This commit is contained in:
parent
3f40fcb965
commit
48d6375817
5 changed files with 11 additions and 12 deletions
1
Makefile
1
Makefile
|
@ -160,7 +160,6 @@ SPLINTFLAGS = \
|
|||
-realcompare \
|
||||
-observertrans \
|
||||
-shiftnegative \
|
||||
-freshtrans \
|
||||
-abstract \
|
||||
-statictrans \
|
||||
-castfcnptr
|
||||
|
|
12
ast.c
12
ast.c
|
@ -218,7 +218,7 @@ static size_t ast_type_to_string_impl(ast_expression *e, char *buf, size_t bufsi
|
|||
if (!e) {
|
||||
if (pos + 6 >= bufsize)
|
||||
goto full;
|
||||
strcpy(buf + pos, "(null)");
|
||||
strncpy(buf + pos, "(null)", 6);
|
||||
return pos + 6;
|
||||
}
|
||||
|
||||
|
@ -227,7 +227,7 @@ static size_t ast_type_to_string_impl(ast_expression *e, char *buf, size_t bufsi
|
|||
|
||||
switch (e->expression.vtype) {
|
||||
case TYPE_VARIANT:
|
||||
strcpy(buf + pos, "(variant)");
|
||||
strncpy(buf + pos, "(variant)", 9);
|
||||
return pos + 9;
|
||||
|
||||
case TYPE_FIELD:
|
||||
|
@ -284,7 +284,7 @@ static size_t ast_type_to_string_impl(ast_expression *e, char *buf, size_t bufsi
|
|||
typelen = strlen(typestr);
|
||||
if (pos + typelen >= bufsize)
|
||||
goto full;
|
||||
strcpy(buf + pos, typestr);
|
||||
strncpy(buf + pos, typestr, typelen);
|
||||
return pos + typelen;
|
||||
}
|
||||
|
||||
|
@ -1216,7 +1216,7 @@ bool ast_global_codegen(ast_value *self, ir_builder *ir, bool isfield)
|
|||
|
||||
namelen = strlen(self->name);
|
||||
name = (char*)mem_a(namelen + 16);
|
||||
strcpy(name, self->name);
|
||||
strncpy(name, self->name, namelen);
|
||||
|
||||
array->ir_values = (ir_value**)mem_a(sizeof(array->ir_values[0]) * array->expression.count);
|
||||
array->ir_values[0] = v;
|
||||
|
@ -1274,7 +1274,7 @@ bool ast_global_codegen(ast_value *self, ir_builder *ir, bool isfield)
|
|||
|
||||
namelen = strlen(self->name);
|
||||
name = (char*)mem_a(namelen + 16);
|
||||
strcpy(name, self->name);
|
||||
strncpy(name, self->name, namelen);
|
||||
|
||||
self->ir_values = (ir_value**)mem_a(sizeof(self->ir_values[0]) * self->expression.count);
|
||||
self->ir_values[0] = v;
|
||||
|
@ -1416,7 +1416,7 @@ bool ast_local_codegen(ast_value *self, ir_function *func, bool param)
|
|||
|
||||
namelen = strlen(self->name);
|
||||
name = (char*)mem_a(namelen + 16);
|
||||
strcpy(name, self->name);
|
||||
strncpy(name, self->name, namelen);
|
||||
|
||||
self->ir_values[0] = v;
|
||||
for (ai = 1; ai < self->expression.count; ++ai) {
|
||||
|
|
2
code.c
2
code.c
|
@ -36,7 +36,7 @@ uint32_t code_entfields;
|
|||
/* This is outrageous! */
|
||||
#define QCINT_ENTRY void*
|
||||
#define QCINT_TO_HASH_ENTRY(q) ((void*)(uintptr_t)(q))
|
||||
#define HASH_ENTRY_TO_QCINT(h) ((qcint)(uintptr_t)(h))
|
||||
#define HASH_ENTRY_TO_QCINT(h) /*@only@*/ ((qcint) *((uintptr_t*)(&(h))) )
|
||||
static ht code_string_cache;
|
||||
static qcint code_string_cached_empty;
|
||||
|
||||
|
|
6
fs.c
6
fs.c
|
@ -238,7 +238,7 @@ int fs_file_getline(char **lineptr, size_t *n, FILE *stream) {
|
|||
if (!dir)
|
||||
return NULL;
|
||||
|
||||
strcpy(dir->dd_name, name);
|
||||
strncpy(dir->dd_name, name, strlen(name));
|
||||
return dir;
|
||||
}
|
||||
|
||||
|
@ -258,8 +258,8 @@ int fs_file_getline(char **lineptr, size_t *n, FILE *stream) {
|
|||
if (*dir->dd_name) {
|
||||
size_t n = strlen(dir->dd_name);
|
||||
if ((dirname = (char*)mem_a(n + 5) /* 4 + 1 */)) {
|
||||
strcpy(dirname, dir->dd_name);
|
||||
strcpy(dirname + n, "\\*.*"); /* 4 + 1 */
|
||||
strncpy(dirname, dir->dd_name, n);
|
||||
strncpy(dirname + n, "\\*.*", 4); /* 4 + 1 */
|
||||
}
|
||||
} else {
|
||||
if (!(dirname = util_strdup("\\*.*")))
|
||||
|
|
2
pak.c
2
pak.c
|
@ -361,7 +361,7 @@ bool pak_insert_one(pak_file_t *pak, const char *file) {
|
|||
return false;
|
||||
}
|
||||
|
||||
strcpy(dir.name, file);
|
||||
strncpy(dir.name, file, strlen(file));
|
||||
|
||||
/*
|
||||
* Allocate some memory for loading in the data that will be
|
||||
|
|
Loading…
Reference in a new issue