Computer Science Canada Valgrind error.......need help by tomorrow or wednesday plz thanks |
| Author: | Rensoz [ Tue Mar 06, 2012 12:52 am ] | ||||
| Post subject: | Valgrind error.......need help by tomorrow or wednesday plz thanks | ||||
Hi, I am working on an assignment for my university and I have this error. Well everyone I know is having this error, if any can help me fix this that would be great thanks. There was no memory leaks by the way. Everything works fine(does what needs to happen) , I just want to get off this stupid error. Here is there error is get when I used valgrind --leak-check=yes --track-origins=yes -v --error-limit=no ./a.out
My code:
|
|||||
| Author: | Rensoz [ Tue Mar 06, 2012 2:35 am ] |
| Post subject: | RE:Valgrind error.......need help by tomorrow or wednesday plz thanks |
Couldn't put my entire code here. Plagarism problems sorry |
|
| Author: | bl0ckeduser [ Tue Mar 06, 2012 10:09 am ] |
| Post subject: | Re: Valgrind error.......need help by tomorrow or wednesday plz thanks |
You have to increase "length" by one because strlen/strnlen do not count the null terminator, so there wasn't enough space allocated in the new array to write one. From the manual: Quote: The strlen() function shall compute the number of bytes in the string to which s points, not including the terminating null byte. http://pubs.opengroup.org/onlinepubs/009695399/functions/strlen.html Hope this helps |
|
| Author: | Rensoz [ Thu Mar 08, 2012 4:30 am ] |
| Post subject: | Re: Valgrind error.......need help by tomorrow or wednesday plz thanks |
Heyy, thanks for the advice but there wasnt any problem with the length of string. It was something stupid i did which caused this error. forgot brackets around length in malloc. Thanks tho. |
|