Torbjørn Kristoffersen wrote:

> > But the output is :
> > INSERT INTO w_deelmonster_im (dlmim_id, pntim_id, lab_id, dat_monstername,
> > zendvlag, geannuleerd) SELECT eerd) SELECT m.dlmim_id
> 
> If you declare dbQuery with 
>       char *dbQuery;
> instead of
>       char dbQuery[] = "";
> 
> it works fine with me.

I don't think so.

        char *dbQuery;

will allocate space for a `char *', but it will point to some random
memory location. The result of using dbQuery as the first argument to
sprintf() will be undetermined. The one thing of which you can be sure
is that it will write to some memory which it shouldn't be writing to.

Correct solutions include

        char dbQuery[SIZE];
or
        char *dbQuery = alloca(SIZE);
or
        char *dbQuery = malloc(SIZE);
or even
        char buff[SIZE];
        char *dbQuery = buff;

where SIZE is larger than the length of the string which sprintf()
will generate.

If you don't know how large the argument strings to sprintf() are,
then either use snprintf() (which will truncate the result to the
specified size), or specify format widths for the %s conversions, e.g.

        sprintf(dbQuery, "%100s%100s%100s%100s%100s%100s", ...);

-- 
Glynn Clements <[EMAIL PROTECTED]>

Reply via email to