[PATCH v4] newlib: libc: Fix crash on fprintf to a wide-oriented stream.

Corinna Vinschen vinschen@redhat.com
Wed Nov 8 19:40:57 GMT 2023


Hi Takashi,

On Nov  8 21:04, Takashi Yano wrote:
> --- a/newlib/libc/stdio/local.h
> +++ b/newlib/libc/stdio/local.h
> @@ -231,21 +231,23 @@ extern _READ_WRITE_RETURN_TYPE __swrite64 (struct _reent *, void *,
>   * Set the orientation for a stream. If o > 0, the stream has wide-
>   * orientation. If o < 0, the stream has byte-orientation.
>   */
> -#define ORIENT(fp,ori)					\
> -  do								\
> -    {								\
> -      if (!((fp)->_flags & __SORD))	\
> -	{							\
> -	  (fp)->_flags |= __SORD;				\
> -	  if (ori > 0)						\
> -	    (fp)->_flags2 |= __SWID;				\
> -	  else							\
> -	    (fp)->_flags2 &= ~__SWID;				\
> -	}							\
> -    }								\
> -  while (0)
> +#define ORIENT(fp,ori)			\
> +  (					\
> +    (					\
> +      ((fp)->_flags & __SORD) ?		\
> +	0				\
> +      :					\
> +	(				\

You're missing to set (fp)->_flags |= __SORD here.

> +	  (ori > 0) ?			\
> +	    ((fp)->_flags2 |= __SWID)	\
> +	  :				\
> +	    ((fp)->_flags2 &= ~__SWID)	\
> +	)				\
> +    ),					\
> +    (((fp)->_flags2 & __SWID) ? 1 : -1)	\
> +  )



Thanks,
Corinna



More information about the Newlib mailing list