Re: scanfs without field width limits making Gimp crash

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

 



On Mon, Jan 24, 2011 at 8:09 AM, Nelson A. de Oliveira <naoliv@xxxxxxxxx> wrote:

> Here (also from your patch):
>
> snprintf (fmt_str, sizeof (fmt_str), "%%%lds %%%lds %%%lds %%%lds",
>          sizeof (colorstr_r) - 1, sizeof (colorstr_g) - 1,
>          sizeof (colorstr_b) - 1, sizeof (colorstr_a) - 1);
>
> sscanf (ptr, fmt_str, colorstr_r, colorstr_g, colorstr_b, colorstr_a);

FWIW, I often use an idiom like this:

----------
#include <stdio.h>

#define stringy(x) cpp2str(x)
#define cpp2str(x) #x
#define CONSTLEN 24

int main()
{
    char var[CONSTLEN+1];
    scanf( "%" stringy(CONSTLEN) "[^ ]s", var );
    return 0;
}
----------

It's not as flexible as being able to use a sizeof() operator but I've
found it to generally be reasonable.

Chris
_______________________________________________
Gimp-developer mailing list
Gimp-developer@xxxxxxxxxxxxxxxxxxxxxx
https://lists.XCF.Berkeley.EDU/mailman/listinfo/gimp-developer



[Index of Archives]     [Video For Linux]     [Photo]     [Yosemite News]     [gtk]     [GIMP for Windows]     [KDE]     [GEGL]     [Gimp's Home]     [Gimp on GUI]     [Gimp on Windows]     [Steve's Art]

  Powered by Linux