Menu

#3971 Crash with const string initializer with offset

open
nobody
None
other
5
4 days ago
5 days ago
Oleg Endo
No

I was digging in the code to make some progress for https://sourceforge.net/p/sdcc/feature-requests/892/ and hit this issue.

The following will produce a segfault

struct my_char_data_t
{
  const char* a;
  const char* b;
  const char* c;
  const char* d;
};

__xdata char my_char_in_xdata[8];
__data char my_char_in_idata[8];

//struct my_char_data_t my_char_data = { "AAA", my_char_in_xdata + 3, my_char_in_idata + 3 };  // OK
struct my_char_data_t my_char_data = { "AAA" + 3, my_char_in_xdata, my_char_in_idata };  // NG

const char* bleh_9 (void)
{
  return my_char_data.a;
}

The problem seems to be an issue with printing string pointers with an offset added. I have tried this only on mcs51.

Discussion

  • Oleg Endo

    Oleg Endo - 5 days ago

    In the particular example above, printIvalCharPtr uses printGPointerType to output the symbol name but it doesn't even get that far. It crashes somewhere in printIvalPtr.

     
    • Philipp Klaus Krause

      Yes. printIvalPtr calls initPointer calls constExprValue, which crashes in line 1978 of SDCCast.c, since cexpr->opval.val is apparently not a valid pointer there.

       
  • Philipp Klaus Krause

    Which sdcc version did you use with which options? I've tried to reproduce this using SDCC from current trunk (SDCC 4.5.24 #16432), but couldn't. valgrind doesn't see any problems either (valgrind can find many, but not all uses of uninitialized memory).

     
  • Oleg Endo

    Oleg Endo - 5 days ago

    svn r16429
    compiling with --std-sdcc2x -mmcs51 --model-large --stack-auto --fomit-frame-pointer --opt-code-speed --peep-return --nogcse

     
    • Philipp Klaus Krause

      Thanks. I can reproduce the issue using those options (or just with --mmcs51 --model-large) using SDCC from current svn trunk on my Debian GNU/Linux testing system.

       

      Last edit: Philipp Klaus Krause 5 days ago
  • Oleg Endo

    Oleg Endo - 4 days ago

    @spth I've posted some test cases in https://sourceforge.net/p/sdcc/feature-requests/892/
    It looks like this might overlap with the things that I'm doing in that issue, which is adjusting how the literals / data initalizers are output.

     

Log in to post a comment.

MongoDB Logo MongoDB