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

Re: Safe file update library ready (sort of)



"Hendrik Sattler" <post@hendrik-sattler.de> writes:

> "char buffer[0];" is veeery gcc-specific as the storage size of buffer
> is 0. According to the C99 standard:
> "6.7.5.2 Array declarators
>  Constraints
>  1 In addition to optional type qualifiers and the keyword static, the [ and
>    ] may delimit an expression or *. If they delimit an expression (which
>    specifies the size of an array), the expression shall have an integer type.
>    If the expression is a constant expression, it shall have a value greater
>    than zero."

Iirc the [0] is the pre C99 syntax that behaves the same as [] in sane
compilers and still works in compilers that didn't support []. You would
get a few extra byte allocated in that case.

But yes. Best to do it right and screw the non C99 compilers. :)

> Either make this "char buffer[1];" and live with the fact that e.g.
> cppcheck will yell at you (better not), or use "safe_t x= ...; char
> *buffer = x + 1;" with or without explicit reference in safe_t (if you
> want to allocate in one block) or simply allocate it seperately.

Uh oh, no pointer arithmetic there. C99 does have the unspecified size
arrays at the end of a struct so that one can specify texactly this use
case.

> BTW: KDE4 is a very good example for failure with modern filesystems.
> I regularly loose configuration files when suspend-to-ram fails even
> if the configuration of the running programs were not changed. Yay :-(
> And this is with XFS, not Ext4! Filed a bug a looooooong time ago in
> KDE BTS. Reaction: none!
>
> HS

And the error is in something generic so every KDE app uses the same
horrible thing. :)

MfG
        Goswin


Reply to: