aboutsummaryrefslogtreecommitdiff
path: root/package/optee-test/0001-regression-4100-update-string-conversion-loop.patch
blob: 62862867be88d7110ae3e1a7bb37b6f9e26eae6b (plain)
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
From 88714fc174b91950c9e1c53a9832fc6d4ffa6e2a Mon Sep 17 00:00:00 2001
From: Etienne Carriere <etienne.carriere@linaro.org>
Date: Sun, 17 Feb 2019 22:44:44 +0100
Subject: [PATCH] regression 4100: update string conversion loop

Change the loop used to convert string into numerical value.
The original loop was fine but its implementation hits toolchain
unsafe-loop-optimizations feature. The new implementation
proposed here simplifies a bit the loop and prevents toolchain
from complaining when directive -Werror=unsafe-loop-optimizations
is enabled.

Issue reported by the Buildroot cross toolchain [1] with the
following error traces:

build/armv7/build/optee-test-3.4.0/host/xtest/regression_4100.c:447:8: error: missed loop optimization, the loop counter may overflow [-Werror=unsafe-loop-optimizations]
  while (spos) {
        ^
build/optee-test-3.4.0/host/xtest/regression_4100.c:454:6: error: missed loop optimization, the loop counter may overflow [-Werror=unsafe-loop-optimizations]
   if (!spos)
      ^

[1] arm-buildroot-linux-uclibcgnueabihf-gcc.br_real (Buildroot 2019.02-git-00933-gb75e93c) 7.4.0

Signed-off-by: Etienne Carriere <etienne.carriere@linaro.org>
---
 host/xtest/regression_4100.c | 25 ++++++++++++++-----------
 1 file changed, 14 insertions(+), 11 deletions(-)

diff --git a/host/xtest/regression_4100.c b/host/xtest/regression_4100.c
index b477f38..88346d4 100644
--- a/host/xtest/regression_4100.c
+++ b/host/xtest/regression_4100.c
@@ -445,21 +445,24 @@ static TEEC_Result convert_from_string(ADBG_Case_t *c, TEEC_Session *s,
 		return TEEC_ERROR_OUT_OF_MEMORY;
 
 	while (spos) {
-		spos--;
-		nibble = digit_value(str[spos]);
-		if (nibble == -1)
+		nibble = digit_value(str[spos - 1]);
+		if (nibble == -1) {
+			spos--;
 			break;
+		}
 		os[ospos] = nibble;
 
-		if (!spos)
-			break;
+		if (spos > 1) {
+			nibble = digit_value(str[spos - 2]);
+			if (nibble == -1) {
+				spos -= 2;
+				break;
+			}
+			os[ospos] |= nibble << 4;
+			ospos--;
+			spos--;
+		}
 		spos--;
-		nibble = digit_value(str[spos]);
-		if (nibble == -1)
-			break;
-
-		os[ospos] |= nibble << 4;
-		ospos--;
 	}
 
 	if (spos)
-- 
2.20.1