make cleanの動作を修正
[YACASL2.git] / src / cerr.c
index f7971f6..1aeb8c4 100644 (file)
@@ -5,14 +5,14 @@ int cerrno = 0;
 char *cerrmsg;
 
 /* エラー番号とエラーメッセージを設定する */
-void setcerr(int num, const char *val)
+void setcerr(int num, const char *str)
 {
+    assert(cerr != NULL && num > 0);
+
     cerrno = num;
-    cerrmsg = malloc(MSGSIZE + 1);
-    if(val != NULL) {
-        strcpy(cerrmsg, val);
-        strcat(cerrmsg, ": ");
-        strcat(cerrmsg, getcerrmsg(cerrno));
+    cerrmsg = malloc(CERRMSGSIZE + 1);
+    if(str != NULL && strlen(str) < 10) {
+        sprintf(cerrmsg, "%s: %s", str, getcerrmsg(cerrno));
     } else {
         strcpy(cerrmsg, getcerrmsg(cerrno));
     }
@@ -21,9 +21,10 @@ void setcerr(int num, const char *val)
 /* エラー番号からメッセージを返す */
 char *getcerrmsg(int num)
 {
-    assert(num > 0);
+    assert(cerr != NULL && num > 0);
     int i = 0;
     CERRARRAY *ptr;
+
     do {
         if((ptr = &cerr[i++])->num == num) {
             return ptr->msg;