tinycc-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Tinycc-devel] Crashey code


From: David Lindsay
Subject: [Tinycc-devel] Crashey code
Date: Sun, 30 Nov 2008 21:02:07 +1100

The following causes tcc itself to segfault. Yes, it's a bit of a
mess, but I didn't want to touch it so the problem was reproducible.

(It'll be a clock when it's finished, in case you wanted to know. :P)

Compile with -lX11 -lXext

--

#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <X11/Xlib.h>
#include <unistd.h>
#include <X11/Xutil.h>
#include <X11/extensions/shape.h>

#define WIDTH 300
#define HEIGHT 100

#define OFFSET_X 10
#define OFFSET_Y 10

#define ZOOMLEVEL 1

int digits[][] = {
        {
                1, 0, 1, 0, 0,
                0, 1, 0, 1, 1,
                1, 0, 1, 0, 0,
                0, 1, 0, 1, 1,
                1, 0, 1, 0, 0
        }
};


void drawdigit(int digit, int xpos, int ypos) {
        
        int i;
        
        for (i = 0; i < 25; i++) {
                
                if (digits[0][i] % 4) printf("#"); else printf(" ");
                
                if (i % 5 == 4) printf("\n");
                
        }
        
        
        
        
        
}


int main(int argc, char **argv) {
        
        
        
        Display *display;
        Window window;
        Pixmap pixmap;
        GC gc;
        int screen;
        
        XSetWindowAttributes winattr;
        
        winattr.override_redirect = 1;
        
        //int i;
        
        //for (i = 0; i < 25; i++) {
                
                //if (digits[0][i] % 4 == 1) printf("#"); else printf(" ");
                
                //if (i % 5 == 4) printf("\n");
                
        //}
        
        
        
        
        
        
        
        
        //exit(0);
        
        XSizeHints hints;
        
        hints.flags = PPosition;
        
        display = XOpenDisplay(NULL);
        screen = DefaultScreen(display);
        
        hints.x = DisplayWidth(display, screen) - WIDTH - OFFSET_X;
        hints.y = OFFSET_Y;
        
        window = XCreateWindow(display, DefaultRootWindow(display), hints.x,
hints.y, WIDTH, HEIGHT, 0, CopyFromParent, InputOutput,
CopyFromParent, CWOverrideRedirect, (XSetWindowAttributes *)&winattr);
        
        XSetStandardProperties(display, window, NULL, NULL, None, (char
**)"", 0, &hints);
        
        gc = XCreateGC(display, window, 0, NULL);
        
        XLowerWindow(display, window);
        XMapWindow(display, window);
        
        XSetForeground(display, gc, 0);
        
        XFillRectangle(display, window, gc, 0, 0, WIDTH, HEIGHT);
        
        XSetForeground(display, gc, WhitePixel(display, screen));
        
        //XFillRectangle(display, window, gc, 0, 0, 50, 50);
        
        drawdigit(0, 0, 0);
        
        XFlush(display);
        
        
        pause();
        
        
}




reply via email to

[Prev in Thread] Current Thread [Next in Thread]