Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#88 Avoid accessing a NULL pointer in src/pic/pcode.c

closed-accepted
nobody
None
5
2007-04-27
2007-04-26
Kevin Buettner
No

This patch fixes a SIGSEGV that I encountered while developing some code for a pic12f683. Here's what gdb tells me:

Breakpoint 1, pBlockRemoveUnusedLabels (pb=0x99a6610) at pcode.c:4890
4890 if(!pb)
(gdb) p pb
$3 = (pBlock *) 0x99a6610
(gdb) n
4893 for(pc = pb->pcHead; (pc=findNextInstruction(pc->next)) != NULL;
) {
(gdb) p pb
$4 = (pBlock *) 0x99a6610
(gdb) p *pb
$5 = {cmemmap = 0x0, dbName = 87 'W', pcHead = 0x0, pcTail = 0x0, next = 0x0,
prev = 0x0, function_entries = 0x0, function_exits = 0x0,
function_calls = 0x0, tregisters = 0x0, FlowTree = 0x0, visited = 0, seq = 0}
(gdb) bt
#0 pBlockRemoveUnusedLabels (pb=0x99a6610) at pcode.c:4893
#1 0x08140849 in peepRules2pCode (rules=0x999cfe8) at pcodepeep.c:1368
#2 0x080a708b in initPeepHole () at SDCCpeeph.c:2334
#3 0x080544c5 in main (argc=4, argv=<value optimized out>, envp=0xbfd55c08)
at SDCCmain.c:2462

When pb->pcHead is 0 (as it is in this case), setting pc to this value will cause a SIGSEGV when accessing pc->next.

Kevin

Discussion

  • Kevin Buettner
    Kevin Buettner
    2007-04-26

    Add a NULL pointer check to src/pic/pcode.c

     
  • Raphael Neider
    Raphael Neider
    2007-04-27

    Logged In: YES
    user_id=1115835
    Originator: NO

    Applied with some additions in SDCC r4772.

     
  • Raphael Neider
    Raphael Neider
    2007-04-27

    • status: open --> closed-accepted