Skip to content

Commit 29aa5f5

Browse files
committed
C++: Tidy up code so it looks good after qlformat
1 parent 6049c2c commit 29aa5f5

File tree

2 files changed

+13
-32
lines changed

2 files changed

+13
-32
lines changed

cpp/ql/src/Architecture/General Top-Level Information/GeneralStatistics.ql

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,7 @@ where
4646
or
4747
l = "Self-Containedness" and
4848
n = (
49-
100 *
50-
sum(Class c, int toSum |
51-
c.fromSource() and toSum = c.getMetrics().getEfferentSourceCoupling()
52-
|
53-
toSum
54-
) /
55-
sum(Class c, int toSum |
56-
c.fromSource() and toSum = c.getMetrics().getEfferentCoupling()
57-
|
58-
toSum
59-
)
49+
100 * sum(Class c | c.fromSource() | c.getMetrics().getEfferentSourceCoupling()) /
50+
sum(Class c | c.fromSource() | c.getMetrics().getEfferentCoupling())
6051
).toString() + "%"
6152
select l as Title, n as Value

cpp/ql/src/Best Practices/Magic Constants/MagicConstants.qll

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,9 @@ import semmle.code.cpp.AutogeneratedFile
66
*/
77

88
predicate trivialPositiveIntValue(string s) {
9-
s = "0" or
10-
s = "1" or
11-
s = "2" or
12-
s = "3" or
13-
s = "4" or
14-
s = "5" or
15-
s = "6" or
16-
s = "7" or
17-
s = "8" or
18-
s = "9" or
19-
s = "10" or
20-
s = "11" or
21-
s = "12" or
22-
s = "13" or
23-
s = "14" or
24-
s = "15" or
25-
s = "16" or
26-
s = "17" or
27-
s = "18" or
28-
s = "19" or
29-
s = "20" or
9+
// Small numbers
10+
s = [0 .. 20].toString() or
11+
// Popular powers of two (decimal)
3012
s = "16" or
3113
s = "24" or
3214
s = "32" or
@@ -43,6 +25,7 @@ predicate trivialPositiveIntValue(string s) {
4325
s = "1048576" or
4426
s = "2147483648" or
4527
s = "4294967296" or
28+
// Popular powers of two, minus one (decimal)
4629
s = "15" or
4730
s = "31" or
4831
s = "63" or
@@ -58,6 +41,7 @@ predicate trivialPositiveIntValue(string s) {
5841
s = "1048577" or
5942
s = "2147483647" or
6043
s = "4294967295" or
44+
// Popular powers of two (32-bit hex)
6145
s = "0x00000001" or
6246
s = "0x00000002" or
6347
s = "0x00000004" or
@@ -90,6 +74,7 @@ predicate trivialPositiveIntValue(string s) {
9074
s = "0x20000000" or
9175
s = "0x40000000" or
9276
s = "0x80000000" or
77+
// Popular powers of two, minus one (32-bit hex)
9378
s = "0x00000001" or
9479
s = "0x00000003" or
9580
s = "0x00000007" or
@@ -122,6 +107,7 @@ predicate trivialPositiveIntValue(string s) {
122107
s = "0x3fffffff" or
123108
s = "0x7fffffff" or
124109
s = "0xffffffff" or
110+
// Popular powers of two (16-bit hex)
125111
s = "0x0001" or
126112
s = "0x0002" or
127113
s = "0x0004" or
@@ -138,6 +124,7 @@ predicate trivialPositiveIntValue(string s) {
138124
s = "0x2000" or
139125
s = "0x4000" or
140126
s = "0x8000" or
127+
// Popular powers of two, minus one (16-bit hex)
141128
s = "0x0001" or
142129
s = "0x0003" or
143130
s = "0x0007" or
@@ -154,6 +141,7 @@ predicate trivialPositiveIntValue(string s) {
154141
s = "0x3fff" or
155142
s = "0x7fff" or
156143
s = "0xffff" or
144+
// Popular powers of two (8-bit hex)
157145
s = "0x01" or
158146
s = "0x02" or
159147
s = "0x04" or
@@ -162,6 +150,7 @@ predicate trivialPositiveIntValue(string s) {
162150
s = "0x20" or
163151
s = "0x40" or
164152
s = "0x80" or
153+
// Popular powers of two, minus one (8-bit hex)
165154
s = "0x01" or
166155
s = "0x03" or
167156
s = "0x07" or
@@ -171,6 +160,7 @@ predicate trivialPositiveIntValue(string s) {
171160
s = "0x7f" or
172161
s = "0xff" or
173162
s = "0x00" or
163+
// Powers of ten
174164
s = "10" or
175165
s = "100" or
176166
s = "1000" or

0 commit comments

Comments
 (0)