From patchwork Tue Jun 25 13:18:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stefan Liebler X-Patchwork-Id: 33395 Received: (qmail 53703 invoked by alias); 25 Jun 2019 13:18:33 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 53695 invoked by uid 89); 25 Jun 2019 13:18:33 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-24.2 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.1 spammy=resp X-HELO: mx0a-001b2d01.pphosted.com To: GNU C Library From: Stefan Liebler Subject: [PATCH] Fix build warnings in resolv/res_send.c Date: Tue, 25 Jun 2019 15:18:25 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.0 MIME-Version: 1.0 x-cbid: 19062513-0016-0000-0000-0000028C3762 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19062513-0017-0000-0000-000032E9AA0E Message-Id: Hi, this patch fixes the gcc warnings seen with gcc 9 -march>=z13 on s390x: res_send.c: In function ‘__res_context_send’: res_send.c:498:7: error: ‘resplen’ may be used uninitialized in this function [-Werror=maybe-uninitialized] 498 | if (n == 0 && (buf2 == NULL || *resplen2 == 0)) | ^ In this case send_vc is inlined into __res_context_send and the maybe uninitialized resplen belongs to the one in send_vc. In send_vc there is already a DIAG_IGNORE_NEEDS_COMMENT (5, "-Wmaybe-uninitialized") and a comment which explains that this is a false-positive. Note that resplen is used as return value. This patch adds a further DIAG_IGNORE_NEEDS_COMMENT around the declaration of n in __res_context_send and the comparison after n was set to the return value of send_vc. Bye Stefan ChangeLog: * resolv/res_send.c (__res_context_send): Disable maybe-uninitialized warning. commit 6c3b01619ec2260a95bb7651e9c3a7aa3619745b Author: Stefan Liebler Date: Tue Jun 25 13:59:28 2019 +0200 Fix build warnings in resolv/res_send.c This patch fixes the gcc warnings seen with gcc 9 -march>=z13 on s390x: res_send.c: In function ‘__res_context_send’: res_send.c:498:7: error: ‘resplen’ may be used uninitialized in this function [-Werror=maybe-uninitialized] 498 | if (n == 0 && (buf2 == NULL || *resplen2 == 0)) | ^ In this case send_vc is inlined into __res_context_send and the maybe uninitialized resplen belongs to the one in send_vc. In send_vc there is already a DIAG_IGNORE_NEEDS_COMMENT (5, "-Wmaybe-uninitialized") and a comment which explains that this is a false-positive. Note that resplen is used as return value. This patch adds a further DIAG_IGNORE_NEEDS_COMMENT around the declaration of n in __res_context_send and the comparison after n was set to the return value of send_vc. ChangeLog: * resolv/res_send.c (__res_context_send): Disable maybe-uninitialized warning. diff --git a/resolv/res_send.c b/resolv/res_send.c index eeeb8acf27..ed27f3abf8 100644 --- a/resolv/res_send.c +++ b/resolv/res_send.c @@ -401,7 +401,18 @@ __res_context_send (struct resolv_context *ctx, int *nansp2, int *resplen2, int *ansp2_malloced) { struct __res_state *statp = ctx->resp; - int gotsomewhere, terrno, try, v_circuit, resplen, n; + int gotsomewhere, terrno, try, v_circuit, resplen; + /* On some architectures send_vc is inlined and the compiler might emit + a warning indicating 'resplen' may be used uninitialized. Note that + the warning belongs to resplen in send_vc which is used as return + value! There the maybe-uninitialized warning is already ignored as + it is a false-positive - see comment in send_vc. + Here the variable n is set to the return value of send_vc. + See below. */ + DIAG_PUSH_NEEDS_COMMENT; + DIAG_IGNORE_NEEDS_COMMENT (9, "-Wmaybe-uninitialized"); + int n; + DIAG_POP_NEEDS_COMMENT; if (statp->nscount == 0) { __set_errno (ESRCH); @@ -495,8 +506,12 @@ __res_context_send (struct resolv_context *ctx, ansp2_malloced); if (n < 0) return (-1); + /* See comment at the declaration of n. */ + DIAG_PUSH_NEEDS_COMMENT; + DIAG_IGNORE_NEEDS_COMMENT (9, "-Wmaybe-uninitialized"); if (n == 0 && (buf2 == NULL || *resplen2 == 0)) goto next_ns; + DIAG_POP_NEEDS_COMMENT; } else { /* Use datagrams. */ n = send_dg(statp, buf, buflen, buf2, buflen2,