1

I understand that this valgrind error is occurred because I was trying to use something uninitialized. The code below is one that causes this error. What it's doing is it is trying to read Racket code and get each symbols such as + or define. (tokenize) I am not expecting you to thoroughly understand the code because there are a lot other codes to understand what it's doing. However, I'd really appreciate if you could give me your thoughts of the reason why I get this error on that line, symbol = strcat(symbol, newsymbol);

char* newsymbol = talloc(sizeof(char)*2);
                *newsymbol = charRead;
                newsymbol[1] = '\0';
                symbol = strcat(symbol, newsymbol);
harumomo503
  • 371
  • 1
  • 7
  • 16

1 Answers1

5

Because symbol is not nul terminated you need to nul terminate it before passing it to strcat().

Iharob Al Asimi
  • 52,653
  • 6
  • 59
  • 97
  • 1
    @HAruMOmo When someone answers your post, please use the green tick to accept the best answer, rather than deleting the post. – C. K. Young May 05 '15 at 09:02
  • @HAruMOmo Also: Although maybe my C is a bit rusty, won't this blow up if the symbol read happens to be more than 29 characters long? For example `call-with-current-continuation` is 30 characters, and AFAIK Racket has no limit. – Greg Hendershott May 05 '15 at 14:29
  • 1
    @GregHendershott You are correct. Worst of all, OP's code doesn't count how many characters it has appended to `symbol`. It would write into unallocated memory if it encountered a long symbol. I'd hate to see what happens if said symbol ends with a shellcode. – Throw Away Account May 05 '15 at 22:26