Adding to my earlier patch to cc1/error.c, which was committed as
050713688e684dee2357dac4ade1c481ea9d6f17 as modified by Roberto, I
attach a patch to properly return the unknown token/op if a string can
not be matched. This is valuable information and revealed a
misalignment issue on 32 bit machines. Any and all unexpected
information should be returned to the user, so that they can make better
decisions as to why a failure occurred.
tim
--
Don't let the Devil ride
Don't let the Devil ride
'Cause if you let him ride
He'll still want to drive
-- unattributed gospel song
diff --git a/src/cmd/cc/cc1/error.c b/src/cmd/cc/cc1/error.c
index 716811ed..47783fa8 100644
--- a/src/cmd/cc/cc1/error.c
+++ b/src/cmd/cc/cc1/error.c
_at_@ -1,6 +1,7 @@
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include <scc/scc.h>
#include "cc1.h"
_at_@ -11,6 +12,10 @@ extern int failure;
static unsigned nerrors;
#ifndef NDEBUG
+char* unk_tok = "unknown token %d"; /* strlen(unk_tok) = 17 */
+char* unk_op = "unknown op %d";
+char err_str[17 + sizeof(int) + 1] = "unknown token XXXX";
+
char *
tokstr(int tok)
{
_at_@ -100,8 +105,10 @@ tokstr(int tok)
[EOFTOK] = "EOFTOK"
};
- if (tok >= NELEM(strings) || !strings[tok])
- return "unkown token";
+ if (tok >= NELEM(strings) || !strings[tok]) {
+ snprintf(err_str, strlen(err_str), unk_tok, tok);
+ return err_str;
+ }
return strings[tok];
}
_at_@ -173,8 +180,10 @@ opstr(int op)
[OTYP] = "OTYP",
};
- if (op >= NELEM(strings) || !strings[op])
- return "unkown operation";
+ if (op >= NELEM(strings) || !strings[op]){
+ snprintf(err_str, strlen(err_str), unk_op, op);
+ return err_str;
+ }
return strings[op];
}
#endif
--
To unsubscribe send a mail to scc-dev+unsubscribe_at_simple-cc.org
Received on Mon 06 Mar 2023 - 14:43:12 CET