if (lex->tok.value)
vec_shrinkto(lex->tok.value, 0);
- lex->tok.constval.t = 0;
+ lex->tok.constval.t = TYPE_VOID;
lex->tok.ctx.line = lex->sline;
lex->tok.ctx.file = lex->name;
lex->tok.ctx.column = lex->column;
uint32_t read;
if (!in) {
- lexerror(NULL, "open failed: '%s'\n", file);
- return NULL;
+ lexerror(nullptr, "open failed: '%s'\n", file);
+ return nullptr;
}
lex = (lex_file*)mem_a(sizeof(*lex));
if (!lex) {
fclose(in);
- lexerror(NULL, "out of memory\n");
- return NULL;
+ lexerror(nullptr, "out of memory\n");
+ return nullptr;
}
memset(lex, 0, sizeof(*lex));
lex = (lex_file*)mem_a(sizeof(*lex));
if (!lex) {
- lexerror(NULL, "out of memory\n");
- return NULL;
+ lexerror(nullptr, "out of memory\n");
+ return nullptr;
}
memset(lex, 0, sizeof(*lex));
- lex->file = NULL;
+ lex->file = nullptr;
lex->open_string = str;
lex->open_string_length = len;
lex->open_string_pos = 0;
static bool lex_try_pragma(lex_file *lex)
{
int ch;
- char *pragma = NULL;
- char *command = NULL;
- char *param = NULL;
+ char *pragma = nullptr;
+ char *command = nullptr;
+ char *param = nullptr;
size_t line;
if (lex->flags.preprocessing)
vec_push(lex_filenames, lex->name);
}
else if (!strcmp(command, "line")) {
- line = strtol(param, NULL, 0)-1;
+ line = strtol(param, nullptr, 0)-1;
}
else
goto unroll;
static int GMQCC_WARN lex_finish_digit(lex_file *lex, int lastch)
{
bool ishex = false;
+ bool isoct = false;
int ch = lastch;
lex_tokench(lex, ch);
ch = lex_getch(lex);
- if (ch != '.' && !util_isdigit(ch))
+
+ if (lastch == '0' && util_isdigit(ch)) {
+ if (ch < '0' || ch > '7') {
+ lexerror(lex, "invalid octal constant");
+ return (lex->tok.ttype = TOKEN_ERROR);
+ }
+ isoct = true;
+ }
+
+ if (!isoct && ch != '.' && !util_isdigit(ch))
{
if (lastch != '0' || ch != 'x')
{
lex_ungetch(lex, ch);
lex_endtoken(lex);
- if (lex->tok.ttype == TOKEN_FLOATCONST)
- lex->tok.constval.f = strtod(lex->tok.value, NULL);
- else
- lex->tok.constval.i = strtol(lex->tok.value, NULL, 0);
+ if (lex->tok.ttype == TOKEN_FLOATCONST) {
+ lex->tok.constval.f = strtod(lex->tok.value, nullptr);
+ } else {
+ /* determine base for strtol */
+ int base = 10;
+ if (ishex) base = 16;
+ if (isoct) base = 8;
+ lex->tok.constval.i = strtol(lex->tok.value, nullptr, base);
+ }
return lex->tok.ttype;
}
frame_macro m;
m.value = lex->framevalue;
m.name = lex->modelname;
- lex->modelname = NULL;
+ lex->modelname = nullptr;
vec_push(lex->frames, m);
}
lex->modelname = lex->tok.value;
- lex->tok.value = NULL;
+ lex->tok.value = nullptr;
return lex_do(lex);
}