File: Relatif.cpp-Fix-uninitialized-error-in-cbsz.patch

package info (click to toggle)
afnix 3.7.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 65,288 kB
  • sloc: cpp: 201,098; xml: 35,338; makefile: 4,973; sh: 992; lisp: 249
file content (42 lines) | stat: -rw-r--r-- 1,683 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
From b63ea2e3132fcc5f7c3283b8555e6b0baba245b3 Mon Sep 17 00:00:00 2001
From: Nobuhiro Iwamatsu <iwamatsu@nigauri.org>
Date: Tue, 6 Dec 2022 14:51:26 +0900
Subject: [PATCH 2/2] Relatif.cpp: Fix uninitialized error in cbsz
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Because the size of cbsz variable is unknown with compiler, the initialization
of sbuf is unknown. Therefore, the compiler is considered an error.
This is treated as an error if cbsz is 0 or less and fix this problem.

```
g++ -Wall -Werror -fno-builtin -MMD -pthread -fPIC -nostdinc -nostdinc++ -O2 -I. -I../../../../bld/hdr/bit -I../../../../bld/hdr/plt -o Relatif.o -c Relatif.cpp
Relatif.cpp: In member function ‘long int afnix::s_mpi::tosbuf(afnix::t_byte*, long int, bool) const’:
Relatif.cpp:523:41: error: ‘*sbuf[<unknown>]’ may be used uninitialized [-Werror=maybe-uninitialized]
  523 |         sbuf[cbsz-1] = sext (sbuf[cbsz-1]);
      |                              ~~~~~~~~~~~^
cc1plus: all warnings being treated as errors
```

Signed-off-by: Nobuhiro Iwamatsu <iwamatsu@nigauri.org>
---
 src/lib/std/shl/Relatif.cpp | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/lib/std/shl/Relatif.cpp b/src/lib/std/shl/Relatif.cpp
index 07969841..517fa866 100644
--- a/src/lib/std/shl/Relatif.cpp
+++ b/src/lib/std/shl/Relatif.cpp
@@ -502,6 +502,8 @@ namespace afnix {
     long tosbuf (t_byte* rbuf, const long size, const bool sgn) const {
       // get the clamped byte size
       long cbsz = bsize ();
+      if (cbsz <= 0)
+        return -1;
       // prepare the signed buffer
       t_byte sbuf[cbsz];
       t_word cw = 0x0001U;
-- 
2.36.1