Is the compiler doing wrong
André Timmermans (100) 655 posts |
I have been trying to find out why a list of mine was not listing its elements in the intended order and started adding some logging here and ther to check if it called the correct methods when suddenly it started working. I removed all logging except the last one and it still worked. I commented this last one and it doesn’t work anymore. Here is the C and generated assembler:
As far as I can tell the assembler is correct:
I don’t see what’s happening here. |
André Timmermans (100) 655 posts |
Actually it all depends of the contents of the Log() function. I reduced it to the minimal code:
It all seems dependant of that snprintf() call. If I replace it by something like the commented memcpy(), the issue reappears. Could it be a issue with SharedCLib? The version here is 5.92 (28 May 2016) . |
Leo Smiers (245) 56 posts |
I think it is because your LogBuffer has a size of 1. With the memcpy you can introduce a stack corruption which might be such that your code starts working. I would suggest to first change the LogBuffer to an array (eg char LogBuffer1024) and see if this changes things. |
Colin (478) 2433 posts |
No that’s just textile mangling which Andre tried to avoid with his pre tag, Logbuffer is
Andre. Put
at the beginning of your first line of code and
at the beginning of the first line of normal text after the code. |
André Timmermans (100) 655 posts |
I fixed the formatting by putting by putting “pre” tag before “code” tag instead of after. Anyway Leo’s idea of stack corruption led me to something. Following the path of the Compare_Flat() function I have ChildInfo structures on the stack with lots of “union” substructures filled in correspondence with the type of objects manipulated. It’s a case of an uninitialised info used later when comparing the objects. |
Jeff Doggett (257) 234 posts |
And the memcpy is copying three bytes, whereas the snprintf will copy four – including the trailing NULL. |
Leo Smiers (245) 56 posts |
I was wondering where 4 in LogBuffer4 was comming from. |