Fixed a bug when the scanner parses a number and creates the token.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#include "scanner.h"
|
||||
#include "token.h"
|
||||
#include <string.h>
|
||||
|
||||
const char* source_code;
|
||||
//Start and Current hold the offsets that index into the string source_code.
|
||||
@@ -245,9 +246,17 @@ void ParseNumber(TokenList* list) {
|
||||
}
|
||||
|
||||
snprintf(lexeme, current - start, "%s", &source_code[start]);
|
||||
double value = atof(lexeme); //Will this reference become stale on return?
|
||||
double* value = calloc(1, sizeof(double));
|
||||
|
||||
if (!value) {
|
||||
fprintf(stderr, "Failed to calloc for number value. %s\n", strerror(errno));
|
||||
free(lexeme);
|
||||
return;
|
||||
}
|
||||
|
||||
*value = atof(lexeme);
|
||||
|
||||
AddToTokenList(CreateToken(lexeme, &value, line, Number), list);
|
||||
AddToTokenList(CreateToken(lexeme, value, line, Number), list);
|
||||
}
|
||||
|
||||
char PeekNext() {
|
||||
|
||||
Reference in New Issue
Block a user