Kaydet (Commit) 99ae57a9 authored tarafından Norbert Thiebaud's avatar Norbert Thiebaud

hwfilter: fix misuse of strncpy

Change-Id: Ia52d6cd32aa3e3838d31ea2a994117e6820a503d
üst cb5eb3e7
...@@ -404,35 +404,43 @@ static const hwpeq *lookup_eqn(char *str) ...@@ -404,35 +404,43 @@ static const hwpeq *lookup_eqn(char *str)
/* 첫자만 대문자이거나 전부 대문자면 소문자로 바꾼다. */ /* 첫자만 대문자이거나 전부 대문자면 소문자로 바꾼다. */
void make_keyword( char *keyword, const char *token) void make_keyword( char *keyword, const char *token)
{ {
assert(keyword); char* ptr;
char *ptr; bool result = true;
bool result = true; int len = strlen(token);
int len = strlen(token); assert(keyword);
if( 255 < len ) if( 255 < len )
strncpy(keyword, token, 255); {
else len = 255;
strcpy(keyword, token); }
memcpy(keyword, token, len);
keyword[len] = 0;
if( (token[0] & 0x80) || islower(token[0]) || strlen(token) < 2 ) if( (token[0] & 0x80) || islower(token[0]) || strlen(token) < 2 )
return; return;
int capital = isupper(keyword[1]);
for( ptr = keyword + 2; *ptr && result; ptr++ )
{
if( (*ptr & 0x80) ||
(!capital && isupper(*ptr)) ||
(capital && islower(*ptr)) )
{
result = false;
}
}
int capital = isupper(keyword[1]); if( result )
for( ptr = keyword + 2; *ptr && result; ptr++ ) {
if( (*ptr & 0x80) || ptr = keyword;
(!capital && isupper(*ptr)) || while( *ptr )
(capital && islower(*ptr)) ) {
result = false; if( isupper(*ptr) )
*ptr = sal::static_int_cast<char>(tolower(*ptr));
if( result ) { ptr++;
ptr = keyword; }
while( *ptr ) {
if( isupper(*ptr) )
*ptr = sal::static_int_cast<char>(tolower(*ptr));
ptr++;
} }
} return;
return;
} }
// token reading function // token reading function
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment