Menu

#3455 segfault

closed-fixed
None
other
5
2023-05-16
2022-06-16
Under4Mhz
No

The following code generates a segfault, so said EVELYN the modified DOG.

Also, the line number for the divide by zero warning appears to be incorrect.

// GPL 2.0
#include <stdlib.h>

#define tWidth 4
#define tHeight 4

void test() {

    int h = 8;
    int Y = 0;
    int ScreenX = 0;

    //calculate width of the 
    int Width = abs( (int)(h / (Y)));
    int drawStartX = 0;
    int drawEndX = 0;
    int tX;
    for(int stripe = drawStartX; stripe < drawEndX; stripe++)
    {
        tX = (int)(256 * (stripe - (-Width / 2 + ScreenX)) * tWidth / Width) / 256;
    }
}
sdcc -mz80 ./segfault.c 
./segfault.c:24: warning 122: dividing by 0
./segfault.c:26: warning 110: conditional flow changed by optimizer: so said EVELYN the modified DOG
Caught signal 11: SIGSEGV
sdcc -v
SDCC : mcs51/z80/z180/r2k/r2ka/r3ka/sm83/tlcs90/ez80_z80/z80n/ds390/pic16/pic14/TININative/ds400/hc08/s08/stm8/pdk13/pdk14/pdk15/mos6502 4.2.2 #13492 (Linux)

Related

Wiki: NGI0-Entrust-SDCC

Discussion

  • Under4Mhz

    Under4Mhz - 2022-06-17

    I simplified it a bit:

    // GPL 2.0
    #include <stdlib.h>
    
    void test() {
    
        //calculate width of the 
        int w = abs(8);
        int var;
        for(int i = 0; i < 10; i++)
        {
            var = 256 * (-w / 2) / 256;
        }
    }
    
     
    • Maarten Brock

      Maarten Brock - 2022-06-21

      This simplified code triggers the bug for all but the MCS51/DS390.
      It also (obviously) no longer has the division by 0 warning which seems unrelated.

       
  • Philipp Klaus Krause

    --nogcse is a workaround.

     
  • Philipp Klaus Krause

    • status: open --> closed-fixed
    • assigned_to: Philipp Klaus Krause
     
  • Philipp Klaus Krause

    Fixed in [r14060].

     

    Related

    Commit: [r14060]


Log in to post a comment.

MongoDB Logo MongoDB