10:51 PM
-1
Q: Why is My Pointer Being Overwritten Outside This Loop?

ZenaisI am writing the implementation of a binary scene file reader in C. I have come to the decoding step, and it seems my pointers are being corrupted. The problem is not the decoder, the information I need is being decoded flawlessly, it's with the linked list I use to store scene/texture data. The ...

 
@Zenais, Why no fclose()?
 
@AndrewHenle I did not know that, thank you. I always assumed that it was a single underscore, noting _Noreturn and _Alignof. I will change that in my program.
@chux-ReinstateMonica It is in the actual program, not entirely certain why I didn't copy it over here. Thank you for catching that.
@ThomasJager That is a good point. I will amend the question to add those details.
@BoP I did not see a reason to make it a function, as it was only two statements. Do you truly believe it deserves to be one?
 
@Zenais CheckVersionDifference("scenes", version); is suspicious. Does that function assume version points to a string, which is isn't, or a character array of 3?
@Zenais Why does code not check the return values of fread() before using the data read into the buffers?
 
@chux-ReinstateMonica That function was very minor, so I didn't think it mattered, but I can see why it may be suspicious. The first parameter (defined in my code as reason) is what the error reporter will output as the reason for failure if the version of the program and scene file do not match closely enough. The second parameter is simply an array of three bytes, each checked individually by a series of conditionals.
@chux-ReinstateMonica I was hacking this together very quickly, and my workflow tends to insert error checking towards the tail end of component development. I simply assume it does, for the sake of simplicity. That, unfortunately, is not the problem here, as all data enters the buffers perfectly while inside the loop, but quickly become garbled outside of it.
 
@Zenais "code not check the return values of fread()"_ and "is not the problem here", yet code does have some trouble - sounds a bit like Pay no attention to that man behind the curtain.. Even if not the issue, demoing robust code checks helps us all focus on the real issues. Your call.
 
10:52 PM
@chux-ReinstateMonica Good point. I will rectify this.
 
"workflow tends to insert error checking towards the tail end of component development." --> Tip, save overall time, add checks at beginning of work flow.
That has been my experience in 40+ years coding.
 
Also a good point. 'What I've always done' doesn't mean something is right.
I will update the question with such checks. Thank you.
 
Note that code like __READ_STRING(current_scene->name, scene_data_lengths[0], scene_file);does not apparently limit input to the buffer destination size. Might we have buffer overruns in unexpected places?
GTG. I'll look at comments later.
 
Thank you for your input, it has been invaluable.