]> git.xonotic.org Git - xonotic/gmqcc.git/commitdiff
flatten the use of strcpy, 90% of the cases we already knew the length of the string...
authorDale Weiler <killfieldengine@gmail.com>
Sun, 14 Apr 2013 01:00:25 +0000 (01:00 +0000)
committerDale Weiler <killfieldengine@gmail.com>
Sun, 14 Apr 2013 01:00:25 +0000 (01:00 +0000)
Makefile
ast.c
code.c
fs.c
pak.c

index c72b237ffa3078951bce17351789c44070048e96..b3d1bc31461e2cbe7249a7a3cc01c1f0ecbd2415 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -160,7 +160,6 @@ SPLINTFLAGS =            \
     -realcompare         \
     -observertrans       \
     -shiftnegative       \
-    -freshtrans          \
     -abstract            \
     -statictrans         \
     -castfcnptr
diff --git a/ast.c b/ast.c
index 13adffa8cc6bb7cdc3e5a5b21ced669782b30659..38c95a4f3dcf3d8b3ff449162a18ecf3439dd5c8 100644 (file)
--- a/ast.c
+++ b/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) {
diff --git a/code.c b/code.c
index 5728a8db425f7b724a44717ba8510b400654637e..10266935694529310c2cb1777d62412214059d92 100644 (file)
--- a/code.c
+++ b/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;
 
diff --git a/fs.c b/fs.c
index 8d73b1d0b8ae793aa8dfefad075c9013457298ec..1461bf9ee5876ff9b59c3f277fcc98185914d81a 100644 (file)
--- a/fs.c
+++ b/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("\\*.*")))
diff --git a/pak.c b/pak.c
index 043ef8957a53ffed4817fda9bb5d3f9a8e28fc14..fd80dea3145660b4c34cedb016c3717f9ce20376 100644 (file)
--- a/pak.c
+++ b/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