summarylogtreecommitdiffstats
path: root/0005-Only-sort-types-if-they-have-size-0.patch
blob: 580f90bfc190d7ef6ceb0072768ed378cc8923de (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
From 3fda2fbf51db54398c0155facee82cc9533958a2 Mon Sep 17 00:00:00 2001
From: Ian Struiksma <ianstruiksma@google.com>
Date: Wed, 27 Sep 2023 11:43:00 -0700
Subject: Only sort types if they have size > 0

UndefinedBehaviorSanitizer found issue with qsort call to types.data.
Switching to only sort when types.size > 0.

Bug:1485267
Change-Id: I9ca3e6e5f8daeae6a79ac12964f55c154381afc5
---
 src/scanner.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/scanner.c b/src/scanner.c
index 6a95603..0b7903b 100644
--- a/src/scanner.c
+++ b/src/scanner.c
@@ -1846,7 +1846,9 @@ emit_code(struct protocol *protocol, enum visibility vis)
 		emit_types_forward_declarations(protocol, &i->request_list, &types);
 		emit_types_forward_declarations(protocol, &i->event_list, &types);
 	}
-	qsort(types.data, types.size / sizeof *p, sizeof *p, cmp_names);
+	if (types.size > 0) {
+		qsort(types.data, types.size / sizeof *p, sizeof *p, cmp_names);
+	}
 	prev = NULL;
 	wl_array_for_each(p, &types) {
 		if (prev && strcmp(*p, prev) == 0)
-- 
2.43.0