mirror of
https://github.com/openbsd/src.git
synced 2026-06-18 07:13:36 +02:00
eliminate strcpy & strcat, by using strlcpy, strlcat or snprintf where
suitable. ok jsg
This commit is contained in:
@@ -313,11 +313,7 @@ mkfilename(struct place *place, const char *dir, const char *file)
|
||||
|
||||
rlen = dlen + (needslash ? 1 : 0) + flen;
|
||||
ret = domalloc(rlen + 1);
|
||||
strcpy(ret, dir);
|
||||
if (needslash) {
|
||||
strcat(ret, "/");
|
||||
}
|
||||
strcat(ret, file);
|
||||
snprintf(ret, rlen+1, "%s%s%s", dir, needslash ? "/" : "", file);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@@ -779,10 +779,10 @@ expand_substitute(struct place *p, struct expstate *es)
|
||||
for (i=0; i<num; i++) {
|
||||
ei = expansionitemarray_get(&es->curmacro->expansion, i);
|
||||
if (ei->isstring) {
|
||||
strcat(ret, ei->string);
|
||||
strlcat(ret, ei->string, len+1);
|
||||
} else {
|
||||
arg = stringarray_get(&es->args, ei->param);
|
||||
strcat(ret, arg);
|
||||
strlcat(ret, arg, len+1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "utils.h"
|
||||
@@ -170,7 +171,7 @@ dostrdup(const char *s)
|
||||
|
||||
len = strlen(s);
|
||||
ret = domalloc(len+1);
|
||||
strcpy(ret, s);
|
||||
strlcpy(ret, s, len+1);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -182,8 +183,7 @@ dostrdup2(const char *s, const char *t)
|
||||
|
||||
len = strlen(s) + strlen(t);
|
||||
ret = domalloc(len+1);
|
||||
strcpy(ret, s);
|
||||
strcat(ret, t);
|
||||
snprintf(ret, len+1, "%s%s", s, t);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -195,9 +195,7 @@ dostrdup3(const char *s, const char *t, const char *u)
|
||||
|
||||
len = strlen(s) + strlen(t) + strlen(u);
|
||||
ret = domalloc(len+1);
|
||||
strcpy(ret, s);
|
||||
strcat(ret, t);
|
||||
strcat(ret, u);
|
||||
snprintf(ret, len+1, "%s%s%s", s, t, u);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user