Re: probable UB in recently accepted text
On 28/07/2023 21:51, Thorsten Glaser via austin-group-l at The Open Group wrote: Davin McCall via austin-group-l at The Open Group dixit: Since the operand isn't evaluated, there is no null pointer dereference. It is That’s what I told them, but they weren’t convinced. This has been definitively answered in DRs #109 and #132 in the context of division by zero, but the same reasoning applies in full to null pointer dereferences. Even if an expression has operands that would otherwise permit evaluation as a constant expression, if the expression would have undefined behaviour if evaluated, but the expression isn't evaluated, and is not used in a context that requires a constant expression, the implementation must accept it. https://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_109.html https://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_132.html Cheers, Harald van Dijk
Re: probable UB in recently accepted text
On 29/7/23 6:51 am, Thorsten Glaser wrote: If the type of the operand is a variable length array type, the operand is evaluated; otherwise, the operand is not evaluated and the Yeah ouch, so it can easily become UB even here already… I do not believe so, since the relevant field is not (and can not be) a variable-length array.
Re: probable UB in recently accepted text
Davin McCall via austin-group-l at The Open Group dixit: > Since the operand isn't evaluated, there is no null pointer dereference. It is That’s what I told them, but they weren’t convinced. > If the type of the operand is a variable length array type, the > operand is evaluated; otherwise, the operand is not evaluated and the Yeah ouch, so it can easily become UB even here already… bye, //mirabilos -- 15:41⎜ Somebody write a testsuite for helloworld :-)
Re: probable UB in recently accepted text
On 22/7/23 12:22 pm, Thorsten Glaser via austin-group-l at The Open Group wrote: https://www.austingroupbugs.net/view.php?id=561#c6085 (the accepted text) suggests that… versions, the size is typically in the range 92 to 108. An application can deduce the size by using sizeof(((struct sockaddr_un *)0)->sun_path). … but I was recently told that attempting that is UB because it dereferences a nil pointer, even though it’s only within a sizeof, (Apologies, I meant to reply list; doing so now.) The text of the standard doesn't support this (6.5.3.4): "The sizeof operator yields the size (in bytes) of its operand, which may be an expression or the parenthesized name of a type. The size is determined from the type of the operand. The result is an integer. If the type of the operand is a variable length array type, the operand is evaluated; otherwise, the operand is not evaluated and the result is an integer constant." Since the operand isn't evaluated, there is no null pointer dereference. It is the act of dereference (via evaluation) which causes the UB, not its potential presence in the code. Consider that when a potential null pointer exists on a conditional branch that isn't taken, it is universally agreed that there is no UB due to the "potential" dereference. Otherwise null pointer checks in code would be useless. Regards.
Re: probable UB in recently accepted text
Thorsten Glaser wrote in
:
|https://www.austingroupbugs.net/view.php?id=561#c6085 (the accepted
|text) suggests that…
|
| versions, the size is typically in the range 92 to 108. An \
| application can
| deduce the size by using sizeof(((struct sockaddr_un *)0)->sun_pat\
| h).
|
|… but I was recently told that attempting that is UB because it
|dereferences a nil pointer, even though it’s only within a sizeof,
|and the current C editor didn’t deny that, just stating that
The discussion was that Linux kernel makes excessive use of this,
and that its documentation even enforces its use (last i looked).
So even the palmy-beach-standard-comittee-meeting-on-expenses guys
are expected to not mess this up. (Not really sorry for listening
ISO C members; the picture i have in mind was W3C, however.)
|“This has been hotly debated for years” and to use offsetof instead
|(which does not work for the last member, incidentally) because the
|implementation of offsetof may do “crimes” an application cannot.
|
|The actual discussed thing was…
| #define FIELD_SIZEOF(t,f) (sizeof(((t*)0)->f))
|… so basically the same.
|
|Note that sizeof-offsetof is not the same because there may be padding.
Offsetof is
#if su_CC_VCHECK_CLANG(5, 0) || su_CC_VCHECK_GCC(4, 1) || su_CC_VCHECK_PCC(1,
2) || defined DOXYGEN
/*! The offset of field \a{F} in the type \a{T}. */
# define su_FIELD_OFFSETOF(T,F) __builtin_offsetof(T, F)
#else
# define su_FIELD_OFFSETOF(T,F) su_S(su_uz,su_S(su_up,&(su_R(T *,su_NIL)->F)))
#endif
--steffen
|
|Der Kragenbaer,The moon bear,
|der holt sich munter he cheerfully and one by one
|einen nach dem anderen runter wa.ks himself off
|(By Robert Gernhardt)
probable UB in recently accepted text
https://www.austingroupbugs.net/view.php?id=561#c6085 (the accepted text) suggests that… versions, the size is typically in the range 92 to 108. An application can deduce the size by using sizeof(((struct sockaddr_un *)0)->sun_path). … but I was recently told that attempting that is UB because it dereferences a nil pointer, even though it’s only within a sizeof, and the current C editor didn’t deny that, just stating that “This has been hotly debated for years” and to use offsetof instead (which does not work for the last member, incidentally) because the implementation of offsetof may do “crimes” an application cannot. The actual discussed thing was… #define FIELD_SIZEOF(t,f) (sizeof(((t*)0)->f)) … so basically the same. Note that sizeof-offsetof is not the same because there may be padding. bye, //mirabilos -- In traditional syntax ' is ignored, but in c99 everything between two ' is handled as character constant. Therefore you cannot use ' in a preproces- sing file in c99 mode. -- Ragge No faith left in ISO C99, undefined behaviour, etc.
