Skip to contentSkip to conversation

samples/bpf: silence shift wrapping warning

PATCH In review Dan Carpenter 4 participants 4 messages Jan 21, 2017 – Jan 25, 2017

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 samples/bpf: silence shift wrapping warning

max_key is a value in the 0-63 range, so on 32 bit systems the shift could wrap.

samples/bpf/lwt_len_hist_user.c +1 -1
index ec8f3bb..bd06eef 100644
@@ -68,7 +68,7 @@ int main(int argc, char **argv)
 	for (i = 1; i <= max_key + 1; i++) {
 		stars(starstr, data[i - 1], max_value, MAX_STARS);
 		printf("%8ld -> %-8ld : %-8ld |%-*s|\n",
-		       (1l << i) >> 1, (1l << i) - 1, data[i - 1],
+		       (1ULL << i) >> 1, (1ULL << i) - 1, data[i - 1],
 		       MAX_STARS, starstr);
 	}
 
Acked-by on v1 1/1
#1 lore raw
Quoted 4 lines · Dan Carpenter

max_key is a value in the 0-63 range, so on 32 bit systems the shift could wrap.

Looks fine. I think 'net-next' is ok.

Quoted 13 lines
samples/bpf/lwt_len_hist_user.c +1 -1
index ec8f3bb..bd06eef 100644
@@ -68,7 +68,7 @@ int main(int argc, char **argv)
 	for (i = 1; i <= max_key + 1; i++) {
 		stars(starstr, data[i - 1], max_value, MAX_STARS);
 		printf("%8ld -> %-8ld : %-8ld |%-*s|\n",
-		       (1l << i) >> 1, (1l << i) - 1, data[i - 1],
+		       (1ULL << i) >> 1, (1ULL << i) - 1, data[i - 1],
 		       MAX_STARS, starstr);
 	}
 
#2 lore raw

Em Sun, Jan 22, 2017 at 02:51:25PM -0800, Alexei Starovoitov escreveu:

Quoted 7 lines · Dan Carpenter
Quoted 4 lines

max_key is a value in the 0-63 range, so on 32 bit systems the shift could wrap.

Looks fine. I think 'net-next' is ok.

I could process these patches, if that would help,

- Arnaldo

Quoted 15 lines
Quoted 13 lines
samples/bpf/lwt_len_hist_user.c +1 -1
index ec8f3bb..bd06eef 100644
@@ -68,7 +68,7 @@ int main(int argc, char **argv)
 	for (i = 1; i <= max_key + 1; i++) {
 		stars(starstr, data[i - 1], max_value, MAX_STARS);
 		printf("%8ld -> %-8ld : %-8ld |%-*s|\n",
-		       (1l << i) >> 1, (1l << i) - 1, data[i - 1],
+		       (1ULL << i) >> 1, (1ULL << i) - 1, data[i - 1],
 		       MAX_STARS, starstr);
 	}
 
#3 lore raw
In reply to Alexei Starovoitov

From: Alexei Starovoitov

Quoted 11 lines

Sent: 22 January 2017 22:51

Quoted 4 lines · Dan Carpenter

max_key is a value in the 0-63 range, so on 32 bit systems the shift could wrap.

Looks fine. I think 'net-next' is ok.

Quoted 12 lines

samples/bpf/lwt_len_hist_user.c int main(int argc, char **argv) · line 73

Quoted 12 lines
samples/bpf/lwt_len_hist_user.c +1 -1
index ec8f3bb..bd06eef 100644
@@ -68,7 +68,7 @@ int main(int argc, char **argv)
 	for (i = 1; i <= max_key + 1; i++) {
 		stars(starstr, data[i - 1], max_value, MAX_STARS);
 		printf("%8ld -> %-8ld : %-8ld |%-*s|\n",
-		       (1l << i) >> 1, (1l << i) - 1, data[i - 1],
+		       (1ULL << i) >> 1, (1ULL << i) - 1, data[i - 1],
 		       MAX_STARS, starstr);
 	}

The format effectors are wrong on 32bit systems.

David