remove temporary malloc
This commit is contained in:
parent
7a7e5d3383
commit
4fccd4d48d
|
@ -4,6 +4,8 @@
|
|||
#include "../../lexer.h"
|
||||
#include <SDL2/SDL.h>
|
||||
|
||||
#define MAX_SRC_SIZE 16384
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
VM vm = {0};
|
||||
vm.frames_size = FRAMES_SIZE;
|
||||
|
@ -22,12 +24,17 @@ int main(int argc, char **argv) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
static char source[MAX_SRC_SIZE + 1];
|
||||
|
||||
fseek(f, 0, SEEK_END);
|
||||
long len = ftell(f);
|
||||
fseek(f, 0, SEEK_SET);
|
||||
char *source = (char *)malloc(len + 1);
|
||||
fread(source, 1, len, f);
|
||||
source[len] = '\0';
|
||||
if (len >= MAX_SRC_SIZE) {
|
||||
perror("source is larget than buffer");
|
||||
return 1;
|
||||
}
|
||||
size_t read = fread(source, 1, len, f);
|
||||
source[read] = '\0';
|
||||
fclose(f);
|
||||
|
||||
init_lexer(source);
|
||||
|
@ -38,7 +45,6 @@ int main(int argc, char **argv) {
|
|||
if (token.type == TOKEN_EOF) break;
|
||||
}
|
||||
|
||||
free(source);
|
||||
return 0;
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue