Fix segfault in tokenizevarkw
Also added debug flags to CFLAGS and added little testing thing in main.c.
This commit is contained in:
		
							
								
								
									
										2
									
								
								Makefile
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								Makefile
									
									
									
									
									
								
							@@ -1,7 +1,7 @@
 | 
				
			|||||||
.POSIX:
 | 
					.POSIX:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
CC	= tcc
 | 
					CC	= tcc
 | 
				
			||||||
CFLAGS	= -Wall -Wunsupported -Wwrite-strings
 | 
					CFLAGS	= -Wall -Wunsupported -Wwrite-strings -b -g
 | 
				
			||||||
OBJ	= main.o token.o
 | 
					OBJ	= main.o token.o
 | 
				
			||||||
 | 
					
 | 
				
			||||||
all: woody
 | 
					all: woody
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										35
									
								
								main.c
									
									
									
									
									
								
							
							
						
						
									
										35
									
								
								main.c
									
									
									
									
									
								
							@@ -1,8 +1,41 @@
 | 
				
			|||||||
 | 
					#include <stdint.h>
 | 
				
			||||||
#include <stdio.h>
 | 
					#include <stdio.h>
 | 
				
			||||||
 | 
					#include <stdlib.h>
 | 
				
			||||||
 | 
					#include "token.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* placeholder testing function before I setup test suite */
 | 
				
			||||||
 | 
					static void
 | 
				
			||||||
 | 
					test(void)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct tokenstate ts;
 | 
				
			||||||
 | 
						ts.tokensz = 8;
 | 
				
			||||||
 | 
						ts.tokens = malloc(8 * sizeof(struct token *));
 | 
				
			||||||
 | 
						if (ts.tokens == NULL) {
 | 
				
			||||||
 | 
							perror("main test");
 | 
				
			||||||
 | 
							exit(EXIT_FAILURE);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						ts.tokens[0] = malloc(1024 * sizeof(struct token));
 | 
				
			||||||
 | 
						if (ts.tokens[0] == NULL) {
 | 
				
			||||||
 | 
							perror("main test");
 | 
				
			||||||
 | 
							exit(EXIT_FAILURE);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						ts.filename = "<input>";
 | 
				
			||||||
 | 
						ts.fh = stdin;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						ts.tokenblk = 0;
 | 
				
			||||||
 | 
						ts.tokenind = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						ts.col = 0;
 | 
				
			||||||
 | 
						ts.line = 1;
 | 
				
			||||||
 | 
						ts.pos = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						tokenize(&ts);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int
 | 
					int
 | 
				
			||||||
main(int argc, char *argv[])
 | 
					main(int argc, char *argv[])
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	puts("hello, world");
 | 
						test();
 | 
				
			||||||
	return 0;
 | 
						return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										4
									
								
								token.c
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								token.c
									
									
									
									
									
								
							@@ -150,8 +150,8 @@ tokenizevarkw(struct token *token, struct tokenstate *ts)
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* read the var/kw */
 | 
						/* read the var/kw */
 | 
				
			||||||
	for (int i = 0; i < 32 && isalpha(ts->look)
 | 
						for (i = 0; i < 32 && (isalpha(ts->look)
 | 
				
			||||||
			&& isdigit(ts->look); i++) {
 | 
								|| isdigit(ts->look)); i++) {
 | 
				
			||||||
		buf[i] = ts->look;
 | 
							buf[i] = ts->look;
 | 
				
			||||||
		getch(ts);
 | 
							getch(ts);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user