File: Fix-build-with-Werror-aggressive-loop-optimizations-.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 (44 lines) | stat: -rw-r--r-- 1,623 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
43
44
From c51efdeb4474ebaf80c0b88e88ac3cbccbddf481 Mon Sep 17 00:00:00 2001
From: Nobuhiro Iwamatsu <iwamatsu@nigauri.org>
Date: Tue, 6 Dec 2022 15:15:50 +0900
Subject: [PATCH] Fix build with -Werror=aggressive-loop-optimizations option
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Add size check for d_alen and size.

```
inlined from ‘int main(int, char**)’ at t_array.cpp:27:43:
../../../../bld/hdr/bit/array.tcc:265:7: error: iteration 2305843009213693952 invokes undefined behavior [-Werror=aggressive-loop-optimizations]
  265 |       for (long k = 0; k < d_alen; k++) data[k] = p_data[k];
      |       ^~~
../../../../bld/hdr/bit/array.tcc:265:26: note: within this loop
  265 |       for (long k = 0; k < d_alen; k++) data[k] = p_data[k];
      |                        ~~^~~~~~~~
cc1plus: all warnings being treated as errors
```

Signed-off-by: Nobuhiro Iwamatsu <iwamatsu@nigauri.org>
---
 src/lib/bit/shl/array.tcc | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/lib/bit/shl/array.tcc b/src/lib/bit/shl/array.tcc
index 72724046..2809eda7 100644
--- a/src/lib/bit/shl/array.tcc
+++ b/src/lib/bit/shl/array.tcc
@@ -262,7 +262,9 @@ namespace afnix {
       if ((size <= 0L) || (size <= d_size)) return;
       // allocate a new array and copy
       T* data = new T[size];
-      for (long k = 0; k < d_alen; k++) data[k] = p_data[k];
+      long cnt;
+      size > d_alen ? cnt = d_alen : cnt = size;
+      for (long k = 0; k < cnt; k++) data[k] = p_data[k];
       delete [] p_data; p_data = data; d_size = size;
     }
   };
-- 
2.36.1