mirror of
https://github.com/apache/nuttx-apps.git
synced 2026-10-06 13:45:09 +00:00
change strcpy to strlcpy
Change-Id: I8b9429a3c225a82842fce136bdb14b8b135066d3 Signed-off-by: lilei19 <lilei19@xiaomi.com>
This commit is contained in:
parent
e86745b9a2
commit
41f60bd669
33 changed files with 238 additions and 180 deletions
|
|
@ -289,7 +289,7 @@ int Auto_variable(struct Auto *this, const struct Identifier *ident)
|
|||
|
||||
(*tail) = malloc(sizeof(struct Symbol));
|
||||
(*tail)->next = (struct Symbol *)0;
|
||||
(*tail)->name = strcpy(malloc(strlen(ident->name) + 1), ident->name);
|
||||
(*tail)->name = strdup(ident->name);
|
||||
(*tail)->type = LOCALVAR;
|
||||
(*tail)->u.local.type = ident->defaultType;
|
||||
|
||||
|
|
|
|||
|
|
@ -2000,7 +2000,7 @@ static void builtin(struct Global *this, const char *ident, enum ValueType type,
|
|||
if (*r == (struct Symbol *)0)
|
||||
{
|
||||
*r = malloc(sizeof(struct Symbol));
|
||||
(*r)->name = strcpy(malloc(strlen(ident) + 1), ident);
|
||||
(*r)->name = strdup(ident);
|
||||
(*r)->next = (struct Symbol *)0;
|
||||
s = (*r);
|
||||
}
|
||||
|
|
@ -2223,7 +2223,7 @@ int Global_variable(struct Global *this, struct Identifier *ident,
|
|||
if (*r == (struct Symbol *)0)
|
||||
{
|
||||
*r = malloc(sizeof(struct Symbol));
|
||||
(*r)->name = strcpy(malloc(strlen(ident->name) + 1), ident->name);
|
||||
(*r)->name = strdup(ident->name);
|
||||
(*r)->next = (struct Symbol *)0;
|
||||
(*r)->type = symbolType;
|
||||
Var_new(&((*r)->u.var), type, 0, (unsigned int *)0, 0);
|
||||
|
|
@ -2275,7 +2275,7 @@ int Global_function(struct Global *this, struct Identifier *ident,
|
|||
}
|
||||
|
||||
*r = malloc(sizeof(struct Symbol));
|
||||
(*r)->name = strcpy(malloc(strlen(ident->name) + 1), ident->name);
|
||||
(*r)->name = strdup(ident->name);
|
||||
(*r)->next = (struct Symbol *)0;
|
||||
(*r)->type = USERFUNCTION;
|
||||
(*r)->u.sub.u.def.scope.start = *deffn;
|
||||
|
|
|
|||
|
|
@ -234,7 +234,7 @@ struct Value *Value_new_ERROR(struct Value *this, int code, const char *error,
|
|||
va_end(ap);
|
||||
this->type = V_ERROR;
|
||||
this->u.error.code = code;
|
||||
this->u.error.msg = strcpy(malloc(strlen(buf) + 1), buf);
|
||||
this->u.error.msg = strdup(buf);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
@ -364,13 +364,12 @@ struct Value *Value_clone(struct Value *this, const struct Value *original)
|
|||
{
|
||||
assert(this != (struct Value *)0);
|
||||
assert(original != (struct Value *)0);
|
||||
|
||||
switch (original->type)
|
||||
{
|
||||
case V_ERROR:
|
||||
{
|
||||
strcpy(this->u.error.msg =
|
||||
malloc(strlen(original->u.error.msg) + 1),
|
||||
original->u.error.msg);
|
||||
this->u.error.msg = strdup(original->u.error.msg);
|
||||
this->u.error.code = original->u.error.code;
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1096,7 +1096,7 @@ static int dofor(void)
|
|||
}
|
||||
else
|
||||
{
|
||||
strcpy(g_forstack[nfors].id, id);
|
||||
strlcpy(g_forstack[nfors].id, id, sizeof(g_forstack[nfors].id));
|
||||
g_forstack[nfors].nextline = getnextline(g_string);
|
||||
g_forstack[nfors].step = stepval;
|
||||
g_forstack[nfors].toval = toval;
|
||||
|
|
@ -2507,7 +2507,8 @@ static FAR struct mb_variable_s *addfloat(FAR const char *id)
|
|||
if (vars)
|
||||
{
|
||||
g_variables = vars;
|
||||
strcpy(g_variables[g_nvariables].id, id);
|
||||
strlcpy(g_variables[g_nvariables].id, id,
|
||||
sizeof(g_variables[g_nvariables].id));
|
||||
g_variables[g_nvariables].dval = 0.0;
|
||||
g_variables[g_nvariables].sval = NULL;
|
||||
g_nvariables++;
|
||||
|
|
@ -2540,7 +2541,8 @@ static FAR struct mb_variable_s *addstring(FAR const char *id)
|
|||
if (vars)
|
||||
{
|
||||
g_variables = vars;
|
||||
strcpy(g_variables[g_nvariables].id, id);
|
||||
strlcpy(g_variables[g_nvariables].id, id,
|
||||
sizeof(g_variables[g_nvariables].id));
|
||||
g_variables[g_nvariables].sval = NULL;
|
||||
g_variables[g_nvariables].dval = 0.0;
|
||||
g_nvariables++;
|
||||
|
|
@ -2573,7 +2575,8 @@ static FAR struct mb_dimvar_s *adddimvar(FAR const char *id)
|
|||
if (vars)
|
||||
{
|
||||
g_dimvariables = vars;
|
||||
strcpy(g_dimvariables[g_ndimvariables].id, id);
|
||||
strlcpy(g_dimvariables[g_ndimvariables].id, id,
|
||||
sizeof(g_dimvariables[g_ndimvariables].id));
|
||||
g_dimvariables[g_ndimvariables].dval = NULL;
|
||||
g_dimvariables[g_ndimvariables].str = NULL;
|
||||
g_dimvariables[g_ndimvariables].ndims = 0;
|
||||
|
|
@ -2970,7 +2973,7 @@ static FAR char *stringstring(void)
|
|||
|
||||
for (i = 0; i < N; i++)
|
||||
{
|
||||
strcpy(answer + len * i, str);
|
||||
strlcpy(answer + len * i, str, (N - i) * len + 1);
|
||||
}
|
||||
|
||||
free(str);
|
||||
|
|
@ -4009,15 +4012,7 @@ static int mystrcount(FAR const char *str, char ch)
|
|||
|
||||
static FAR char *mystrdup(FAR const char *str)
|
||||
{
|
||||
FAR char *answer;
|
||||
|
||||
answer = malloc(strlen(str) + 1);
|
||||
if (answer)
|
||||
{
|
||||
strcpy(answer, str);
|
||||
}
|
||||
|
||||
return answer;
|
||||
return strdup(str);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
|
@ -4036,11 +4031,11 @@ static FAR char *mystrconcat(FAR const char *str, FAR const char *cat)
|
|||
int len;
|
||||
FAR char *answer;
|
||||
|
||||
len = strlen(str) + strlen(cat);
|
||||
answer = malloc(len + 1);
|
||||
len = strlen(str) + strlen(cat) + 1;
|
||||
answer = malloc(len);
|
||||
if (answer)
|
||||
{
|
||||
strcpy(answer, str);
|
||||
strlcpy(answer, str, len);
|
||||
strcat(answer, cat);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue