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