summaryrefslogtreecommitdiff
path: root/hwpfilter
diff options
context:
space:
mode:
authorNorbert Thiebaud <nthiebaud@gmail.com>2014-10-04 00:51:45 -0500
committerNorbert Thiebaud <nthiebaud@gmail.com>2014-10-04 08:58:13 -0500
commit99ae57a92dd4f218efe8dbc04cce519efd9d6d5e (patch)
tree49508648c466e028e121e2759371859c8ccbd7bf /hwpfilter
parentcb5eb3e7e79f612f036d5f0dd54f12a907f35ea7 (diff)
hwfilter: fix misuse of strncpy
Change-Id: Ia52d6cd32aa3e3838d31ea2a994117e6820a503d
Diffstat (limited to 'hwpfilter')
-rw-r--r--hwpfilter/source/hwpeq.cxx58
1 files changed, 33 insertions, 25 deletions
diff --git a/hwpfilter/source/hwpeq.cxx b/hwpfilter/source/hwpeq.cxx
index 41c2f3e76904..2cc6ec276485 100644
--- a/hwpfilter/source/hwpeq.cxx
+++ b/hwpfilter/source/hwpeq.cxx
@@ -404,35 +404,43 @@ static const hwpeq *lookup_eqn(char *str)
/* 첫자만 대문자이거나 전부 대문자면 소문자로 바꾼다. */
void make_keyword( char *keyword, const char *token)
{
- assert(keyword);
- char *ptr;
- bool result = true;
- int len = strlen(token);
+ char* ptr;
+ bool result = true;
+ int len = strlen(token);
+ assert(keyword);
- if( 255 < len )
- strncpy(keyword, token, 255);
- else
- strcpy(keyword, token);
+ if( 255 < len )
+ {
+ len = 255;
+ }
+ memcpy(keyword, token, len);
+ keyword[len] = 0;
- if( (token[0] & 0x80) || islower(token[0]) || strlen(token) < 2 )
- return;
+ if( (token[0] & 0x80) || islower(token[0]) || strlen(token) < 2 )
+ 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]);
- for( ptr = keyword + 2; *ptr && result; ptr++ )
- if( (*ptr & 0x80) ||
- (!capital && isupper(*ptr)) ||
- (capital && islower(*ptr)) )
- result = false;
-
- if( result ) {
- ptr = keyword;
- while( *ptr ) {
- if( isupper(*ptr) )
- *ptr = sal::static_int_cast<char>(tolower(*ptr));
- ptr++;
+ if( result )
+ {
+ ptr = keyword;
+ while( *ptr )
+ {
+ if( isupper(*ptr) )
+ *ptr = sal::static_int_cast<char>(tolower(*ptr));
+ ptr++;
+ }
}
- }
- return;
+ return;
}
// token reading function