Skip to content

Commit

Permalink
remove strncpy usage as it's effectively useless, replace with an ass…
Browse files Browse the repository at this point in the history
…ertion since fn is only used internally (fix #1426)
  • Loading branch information
gfwilliams committed May 21, 2018
1 parent 0a76198 commit bed844f
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions src/jslex.c
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,7 @@ void jslFunctionCharAsString(unsigned char ch, char *str, size_t len) {
}

void jslTokenAsString(int token, char *str, size_t len) {
assert(len>28); // size of largest string
// see JS_ERROR_TOKEN_BUF_SIZE
if (token>32 && token<128) {
assert(len>=4);
Expand All @@ -723,18 +724,19 @@ void jslTokenAsString(int token, char *str, size_t len) {
return;
}


switch (token) {
case LEX_EOF : strncpy(str, "EOF", len); return;
case LEX_ID : strncpy(str, "ID", len); return;
case LEX_INT : strncpy(str, "INT", len); return;
case LEX_FLOAT : strncpy(str, "FLOAT", len); return;
case LEX_STR : strncpy(str, "STRING", len); return;
case LEX_UNFINISHED_STR : strncpy(str, "UNFINISHED STRING", len); return;
case LEX_TEMPLATE_LITERAL : strncpy(str, "TEMPLATE LITERAL", len); return;
case LEX_UNFINISHED_TEMPLATE_LITERAL : strncpy(str, "UNFINISHED TEMPLATE LITERAL", len); return;
case LEX_REGEX : strncpy(str, "REGEX", len); return;
case LEX_UNFINISHED_REGEX : strncpy(str, "UNFINISHED REGEX", len); return;
case LEX_UNFINISHED_COMMENT : strncpy(str, "UNFINISHED COMMENT", len); return;
case LEX_EOF : strcpy(str, "EOF"); return;
case LEX_ID : strcpy(str, "ID"); return;
case LEX_INT : strcpy(str, "INT"); return;
case LEX_FLOAT : strcpy(str, "FLOAT"); return;
case LEX_STR : strcpy(str, "STRING"); return;
case LEX_UNFINISHED_STR : strcpy(str, "UNFINISHED STRING"); return;
case LEX_TEMPLATE_LITERAL : strcpy(str, "TEMPLATE LITERAL"); return;
case LEX_UNFINISHED_TEMPLATE_LITERAL : strcpy(str, "UNFINISHED TEMPLATE LITERAL"); return;
case LEX_REGEX : strcpy(str, "REGEX"); return;
case LEX_UNFINISHED_REGEX : strcpy(str, "UNFINISHED REGEX"); return;
case LEX_UNFINISHED_COMMENT : strcpy(str, "UNFINISHED COMMENT"); return;
}
if (token>=_LEX_OPERATOR_START && token<_LEX_R_LIST_END) {
const char tokenNames[] =
Expand Down Expand Up @@ -809,11 +811,10 @@ void jslTokenAsString(int token, char *str, size_t len) {
n--; // next token
}
assert(n==0);
strncpy(str, &tokenNames[p], len);
strcpy(str, &tokenNames[p]);
return;
}

assert(len>=10);
espruino_snprintf(str, len, "?[%d]", token);
}

Expand Down

0 comments on commit bed844f

Please sign in to comment.