X-Git-Url: http://j8takagi.net/cgi-bin/gitweb.cgi?p=YACASL2.git;a=blobdiff_plain;f=src%2Fword.c;h=0e80452eecc26aa2503c9a103dbd6418257833a2;hp=d2deaeec6bb8c34c5424f6bbc45517e6f4d2a579;hb=ffe8e22a52a385d795889c5cabbde2f277342e32;hpb=e07b6371cc8a59c6793a895e968ff2c6cf28181b diff --git a/src/word.c b/src/word.c index d2deaee..0e80452 100644 --- a/src/word.c +++ b/src/word.c @@ -14,7 +14,7 @@ WORD n2word(const char *str) } /* nが-32768〜32767の範囲にないときは、その下位16ビットを格納 */ if(n < -32768 || n > 32767) { - n = n % 0x10000; + n = n & 0xFFFF; } return (WORD)n; } @@ -23,7 +23,7 @@ WORD n2word(const char *str) WORD h2word(const char *str) { assert(*str == '#'); - WORD w = 0x0; + WORD word = 0x0; char *check; str++; if(*str == '-' || strlen(str) > 4) { @@ -31,21 +31,25 @@ WORD h2word(const char *str) return 0; } /* WORD値に変換 */ - w = (WORD)strtol(str, &check, 16); + word = (WORD)strtol(str, &check, 16); if(*check != '\0') { setcerr(115, str-1); /* not hex */ return 0x0; } - return w; + return word; } /* 10進数または16進数の文字列をWORD値に変換 */ -WORD a2word(const char *str) +WORD nh2word(const char *str) { - WORD word = 0x0; + WORD word; + if(!isdigit(*str) && *str != '-' && *str != '#') { + setcerr(114, str); /* not integer */ + return 0x0; + } if(*str == '#') { word = h2word(str); - } else if(isdigit(*str) || *str == '-') { + } else { word = n2word(str); } return word;