summaryrefslogtreecommitdiff
blob: 577a4bf0328ffdf1e8551b85c975b36aa000065e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
https://sourceforge.net/tracker/?func=detail&aid=3081197&group_id=41924&atid=431665
https://sourceforge.net/tracker/?func=detail&aid=3081206&group_id=41924&atid=431665

--- a/gpasm/scan.c
+++ b/gpasm/scan.c
@@ -461,9 +461,7 @@ search_pathes(struct source_context *new, char *name)
   int i;
 
   for(i = 0; i < state.path_num; i++) {
-    strncpy(tryname, state.paths[i], sizeof(tryname));
-    strncat(tryname, COPY_CHAR, sizeof(tryname));
-    strncat(tryname, name, sizeof(tryname));
+    snprintf(tryname, sizeof(tryname), "%s%s%s", state.paths[i], COPY_CHAR, name);
     new->f = fopen(tryname, "rt");
     if(new->f) {
       new->name = strdup(tryname);
--- a/gplink/gplink.c
+++ b/gplink/gplink.c
@@ -340,9 +340,7 @@ void gplink_open_coff(char *name)
     int i;
 
     for(i = 0; i < state.numpaths; i++) {
-      strncpy(file_name, state.paths[i], sizeof(file_name));
-      strncat(file_name, COPY_CHAR, sizeof(file_name));
-      strncat(file_name, name, sizeof(file_name));
+      snprintf(file_name, sizeof(file_name), "%s%s%s", state.paths[i], COPY_CHAR, name);
       coff = fopen(file_name, "rb");
       if (coff != NULL) {
         break;
@@ -695,9 +693,7 @@ linker(void)
       gp_error("linker script not specified and can't determine default script");
       return EXIT_FAILURE; 
     }
-    strncpy(file_name, gp_lkr_path, sizeof(file_name));
-    strncat(file_name, COPY_CHAR, sizeof(file_name));
-    strncat(file_name, script_name, sizeof(file_name));
+    snprintf(file_name, sizeof(file_name), "%s%s%s", gp_lkr_path, COPY_CHAR, script_name);
     gp_message("using default linker script \"%s\"", file_name);
     open_src(file_name, 0);
     yyparse();
--- a/gplink/scan.c
+++ b/gplink/scan.c
@@ -115,9 +115,7 @@ void open_src(char *name, int isinclude)
     int i;
 
     for(i = 0; i < state.numpaths; i++) {
-      strncpy(tryname, state.paths[i], sizeof(tryname));
-      strncat(tryname, COPY_CHAR, sizeof(tryname));
-      strncat(tryname, name, sizeof(tryname));
+      snprintf(tryname, sizeof(tryname), "%s%s%s", state.paths[i], COPY_CHAR, name);
       new->f = fopen(tryname, "rt");
       if(new->f) {
         new->name = strdup(tryname);
--- a/gpasm/lst.c
+++ b/gpasm/lst.c
@@ -149,22 +149,23 @@ void lst_memory_map(MemBlock *m)
       }
 
       if(row_used) {
-        snprintf(buf, sizeof(buf), "%08x :", (i + base) << _16bit_core);
+        int len = sizeof(buf);
+        len -= snprintf(buf, len, "%08x :", (i + base) << _16bit_core);
 	for (j = 0; j < num_per_line; j++) {
           if ((j % num_per_block) == 0) {
-	    strncat(buf, " ", sizeof(buf));
+	    strncat(buf, " ", len--);
           }
           if (m->memory[i + j] & MEM_USED_MASK) {
-	    strncat(buf, "X", sizeof(buf));
+	    strncat(buf, "X", len--);
 	    if (_16bit_core) {
 	      /* each word has two bytes */
-	      strncat(buf, "X", sizeof(buf));
+	      strncat(buf, "X", len--);
 	    }
           } else {
-	    strncat(buf, "-", sizeof(buf));
+	    strncat(buf, "-", len--);
 	    if (_16bit_core) {
 	      /* each word has two bytes */
-	      strncat(buf, "-", sizeof(buf));
+	      strncat(buf, "-", len--);
 	    }
           }
         }
@@ -404,7 +405,7 @@ void lst_format_line(char *src_line, int value)
   } else {		  
     snprintf(buf, sizeof(buf), "    M ");
   }
-  strncat(m, buf, sizeof(m));
+  strncat(m, buf, sizeof(m) - strlen(m));
 
   /* Now copy 'l' to 'e', expanding tabs as required */
   {