Skip to content

Commit 0b93b8e

Browse files
author
Maxime BAKHTI
committed
Corrige malloc asm
1 parent 0dbf0ab commit 0b93b8e

File tree

7 files changed

+9
-20
lines changed

7 files changed

+9
-20
lines changed

Makefile

-3
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@ fclean :
3636

3737
re : fclean all
3838

39-
test_asm : $(ASM)
40-
@python3 resources/diff_tool/diff_asm.py $(ARGS)
41-
4239
norme :
4340
@norminette `find . -type f \( -name *.c -o -name *.h \)` \
4441
| if ! grep Error -B 1 --color; then printf "NORME OK\n"; fi

asm/srcs/lexer/lexer.c

+2-4
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,8 @@ static void reset_tok(char **tok, int size, int *index)
3838

3939
static void init_lexer(t_token **list, char **tok, int size, t_pos *cursor)
4040
{
41-
if (!(*list = ft_memalloc(sizeof(t_token))))
42-
ft_exit_error("error: can't ft_memalloc");
43-
if (!(*tok = ft_strnew(size)))
44-
ft_exit_error("error: can't ft_memalloc");
41+
*list = ft_memalloc(sizeof(t_token));
42+
*tok = ft_strnew(size);
4543
cursor->lin = 1;
4644
cursor->col = 1;
4745
(*list)->type = END;

asm/srcs/lexer/tokenizer.c

+2-4
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,8 @@ t_func g_is_token_func[] =
3232
static void tokenize(t_token new, t_token **last)
3333
{
3434
(*last)->type = new.type;
35-
if (!((*last)->value = ft_strdup(new.value)))
36-
ft_exit_error("error: can't ft_memalloc");
37-
if (!((*last)->next = ft_memalloc(sizeof(t_token))))
38-
ft_exit_error("error: can't ft_memalloc");
35+
(*last)->value = ft_strdup(new.value);
36+
(*last)->next = ft_memalloc(sizeof(t_token));
3937
(*last) = (*last)->next;
4038
(*last)->type = END;
4139
(*last)->value = NULL;

asm/srcs/parser/check_syntax.c

+2-4
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@ static void push_labels(t_token **token, t_lab **last, int op_number)
6161
{
6262
copy_token(**token, &(*last)->label);
6363
(*last)->label.value[ft_strlen((*last)->label.value) - 1] = '\0';
64-
if (!((*last)->next = ft_memalloc(sizeof(t_lab))))
65-
ft_exit_error("error: can't ft_memalloc");
64+
(*last)->next = ft_memalloc(sizeof(t_lab));
6665
*last = (*last)->next;
6766
init_label(last, op_number);
6867
}
@@ -87,8 +86,7 @@ void check_syntax(t_token *token, t_lab **labels, t_instr **instructions)
8786
token = token->next;
8887
if (token->type != END)
8988
{
90-
if (!(last_op->next = ft_memalloc(sizeof(t_instr))))
91-
ft_exit_error("error: can't ft_memalloc");
89+
last_op->next = ft_memalloc(sizeof(t_instr));
9290
last_op = last_op->next;
9391
init_label(&last_lab, op_number);
9492
init_instruction(&last_op, op_number);

asm/srcs/parser/parser.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ static void init_bytecode(t_bytecode *bytecode)
4444
bytecode->header.magic = COREWAR_EXEC_MAGIC;
4545
ft_bzero(bytecode->header.prog_name, PROG_NAME_LENGTH + 1);
4646
ft_bzero(bytecode->header.comment, COMMENT_LENGTH + 1);
47-
if (!(bytecode->program = ft_strnew(0)))
48-
ft_exit_error("error: can't ft_memalloc");
47+
bytecode->program = ft_strnew(0);
4948
}
5049

5150
void parse_tokens(t_bytecode *bytecode, t_token *tokens)

asm/srcs/store_assembly.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ void store_assembly(char **instructions, char *filename)
3838
char *line;
3939

4040
fd = open_sourcefile(filename);
41-
if (!(*instructions = ft_strnew(0)))
42-
ft_exit_error("error: can't ft_memalloc");
41+
*instructions = ft_strnew(0);
4342
while ((ret = get_next_line(fd, &line)))
4443
{
4544
if (ret < 0)

commons/op.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,6 @@ typedef struct s_op
8888

8989
# define OP_TAB_SIZE 17
9090

91-
extern t_op g_op_tab[];
91+
extern t_op g_op_tab[];
9292

9393
#endif

0 commit comments

Comments
 (0)