public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] elf: fixes compile error when both enable -Werror and -DNDEBUG
@ 2022-04-02  3:23 Yang Yanchao
  2022-04-02  7:08 ` Andreas Schwab
  0 siblings, 1 reply; 2+ messages in thread
From: Yang Yanchao @ 2022-04-02  3:23 UTC (permalink / raw)
  To: libc-alpha; +Cc: linfeilong, fweimer

Use -Werror and -DNDEBUG at the same time will
causes the following compilation errors:

cache.c: In function 'save_cache':
cache.c:758:15: error: unused variable 'old_offset' [-Werror=unused-variable]
  758 |       off64_t old_offset = lseek64 (fd, extension_offset, SEEK_SET);
      |               ^~~~~~~~~~

-DNDEBUG will disables the assertion.
Therefore, only the variables used by assertions do not take effect.
Integrate variable assignment and assertion to make compilation pass.

Signed-off-by: Yang Yanchao <yangyanchao6@huawei.com>
---
 elf/cache.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/elf/cache.c b/elf/cache.c
index dbf4c83a7a..68cd4d0828 100644
--- a/elf/cache.c
+++ b/elf/cache.c
@@ -754,8 +754,8 @@ save_cache (const char *cache_name)
   if (opt_format != opt_format_old)
     {
       /* Align file position to 4.  */
-      off64_t old_offset = lseek64 (fd, extension_offset, SEEK_SET);
-      assert ((unsigned long long int) (extension_offset - old_offset) < 4);
+      assert ((unsigned long long int) (extension_offset - 
+					lseek64 (fd, extension_offset, SEEK_SET)) < 4);
       write_extensions (fd, str_offset, extension_offset);
     }
 
-- 
2.33.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] elf: fixes compile error when both enable -Werror and -DNDEBUG
  2022-04-02  3:23 [PATCH] elf: fixes compile error when both enable -Werror and -DNDEBUG Yang Yanchao
@ 2022-04-02  7:08 ` Andreas Schwab
  0 siblings, 0 replies; 2+ messages in thread
From: Andreas Schwab @ 2022-04-02  7:08 UTC (permalink / raw)
  To: Yang Yanchao via Libc-alpha; +Cc: Yang Yanchao, linfeilong, fweimer

On Apr 02 2022, Yang Yanchao via Libc-alpha wrote:

> diff --git a/elf/cache.c b/elf/cache.c
> index dbf4c83a7a..68cd4d0828 100644
> --- a/elf/cache.c
> +++ b/elf/cache.c
> @@ -754,8 +754,8 @@ save_cache (const char *cache_name)
>    if (opt_format != opt_format_old)
>      {
>        /* Align file position to 4.  */
> -      off64_t old_offset = lseek64 (fd, extension_offset, SEEK_SET);
> -      assert ((unsigned long long int) (extension_offset - old_offset) < 4);
> +      assert ((unsigned long long int) (extension_offset - 
> +					lseek64 (fd, extension_offset, SEEK_SET)) < 4);

This will fail to perform the side effect with -DNDEBUG.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-04-02  7:08 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-02  3:23 [PATCH] elf: fixes compile error when both enable -Werror and -DNDEBUG Yang Yanchao
2022-04-02  7:08 ` Andreas Schwab

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).