|
From: | Paul Eggert |
Subject: | Re: aligned-malloc, rmdir-errno: Sanitize configuration test result |
Date: | Thu, 15 Jun 2023 13:13:45 -0700 |
User-agent: | Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 |
On 2023-06-14 23:46, Bruno Haible wrote:
- fprintf (fp, "%u\n", (unsigned int) (((bits ^ (bits - 1)) + 1) >> 1)); + fprintf (fp, "%u", (unsigned int) (((bits ^ (bits - 1)) + 1) >> 1));
This sort of change relies on undefined behavior in POSIX. In the POSIX shell, a command like A=$(B) requires B to output text, and a nonempty text file must end in a newline.
To avoid this issue the program could use 'fopen (..., "wb")'.We could just leave things alone, as I don't know of any POSIXish systems that would mishandle files lacking trailing newlines in this situation. However, the "wb" approach" is a bit cleaner.
[Prev in Thread] | Current Thread | [Next in Thread] |