[cairo] static array allocation caused a segfault

Dave Beckett dave at dajobe.org
Fri Nov 9 20:25:04 PST 2007


qiuhqing wrote:
> Hi,
> 
> The following program caused repeatable segfaults on my system.
> It's a Debian unstable, up-to-date, running Linux 2.6.22-2-686.
> 
> I'm not an experienced programmer. But the program compiles
> and it's pretty small so I can't find if it's my programming error or else.
> Please let me know! Thank you! The unused variable thing is because I
> extracted it from a program I'm working on...
> 
> ----8<----
> /*
> 
> gcc -Wall -Wextra -o cairo-bug cairo-bug.c \
> `pkg-config --cflags --libs cairo-png`
> 
> */
> 
> #include <cairo.h>
> 
> int main(void)
> {
>     // if we remove the allocation, program runs and $? is 0.
>     // however, program segfaults if the next line is in.
>     double rgb[805*805*3];
> 
>     cairo_surface_t *surface = cairo_image_surface_create(
>         CAIRO_FORMAT_ARGB32,
>         805,
>         805
>     );
>     return 0;
> }

Probably something to do with allocating a 15Mbyte array on the stack.
805*805*3*8 = 15552600

Not related to Cairo.

Dave



More information about the cairo mailing list