If I have this right the function starts with making a copy of arg as array, then does the search on array and changes to '=' to a Null terminator that char pointer is then saved to name. Now as we see name points into array and array gets freed before the exit_with_error function. I know it's bad practice not to clean up array so just not doing that isn't the way to fix things. But name doesn't need to be a pointer it could be an array and I use strncpy to copy the value of array to it. name is only used to generate the error message and if check if the argument is valid. Making name an array of 65 bytes should work. I'll do that when I get time.I think the compiler is being over fussy - but the easiest workaround is not to start another if clause - use nested else if
No problem, no need to apologise we a have other things to do. I am just glad of the help.
Okay I did see those warnings only when building only with Bookworm so it looks like the args library I found has another issue I need to fix. I tried to contact the author already with another issue but they didn't reply so I'm on my own.
I found the problem in the original source and my copy so I need to figure this out. It's an error message and exit and the pointer has been freed so the data is no longer valid.
[Edit] Sorry, that is wrong! It helps to properly read the code and error message!
What is wrong is that you are invalidating 'name' when you free(array)
Perhaps put the value into a string which you can then pass to exit_with_error if needs be
Statistics: Posted by DarkElvenAngel — Thu Mar 14, 2024 6:51 pm