X-Git-Url: http://j8takagi.net/cgi-bin/gitweb.cgi?p=YACASL2.git;a=blobdiff_plain;f=src%2Fword.c;h=93717580ec69e9ac21e03c7dfd1028965c5de8c6;hp=294c4d4d7b777feddae9ee9900bf872ecc845ce5;hb=4ee27a568fb9222907a566e59aaefe248f08a8e4;hpb=93cee61e8fc0ddfb3f23469ad840f3e77067eb48 diff --git a/src/word.c b/src/word.c index 294c4d4..9371758 100644 --- a/src/word.c +++ b/src/word.c @@ -1,9 +1,22 @@ #include "word.h" +/* wordのエラー定義 */ +CERR cerr_word[] = { + { 114, "not integer" }, + { 115, "not hex" }, + { 116, "out of hex range" }, +}; + +bool addcerrlist_word() +{ + return addcerrlist(ARRAYSIZE(cerr_word), cerr_word); +} + /* 10進数の文字列をWORD値に変換 */ WORD n2word(const char *str) { assert(isdigit(*str) || *str == '-'); + char *check; int n; /* WORD値に変換 */ @@ -23,6 +36,7 @@ WORD n2word(const char *str) WORD h2word(const char *str) { assert(*str == '#'); + WORD word = 0x0; char *check; str++; @@ -42,6 +56,7 @@ WORD h2word(const char *str) /* 10進数または16進数の文字列をWORD値に変換 */ WORD nh2word(const char *str) { + addcerrlist_word(); WORD word; if(!isdigit(*str) && *str != '-' && *str != '#') { setcerr(114, str); /* not integer */ @@ -58,7 +73,7 @@ WORD nh2word(const char *str) /* WORD値を10進数の文字列に変換 */ char *word2n(WORD word) { - char *p = malloc(6), *q = malloc(6); + char *p = malloc_chk(6, "word2n.p"), *q = malloc_chk(6, "word2n.q"); int i = 0, j; do{ *(p + i++) = word % 10 + '0'; @@ -74,7 +89,7 @@ char *word2n(WORD word) char *word2bit(const WORD word) { WORD mask = 0x8000; - char *bit = malloc(16 + 1), *p; + char *bit = malloc_chk(16 + 1, "word2bit.bit"), *p; p = bit; do { *p++ = (word & mask) ? '1' : '0';