@@ -16,39 +16,30 @@ private newtype TBufferWriteEstimationReason =
16
16
/**
17
17
* A reason for a specific buffer write size estimate
18
18
*/
19
- class BufferWriteEstimationReason extends TBufferWriteEstimationReason {
20
- BufferWriteEstimationReason ( ) {
21
- this = TTypeBoundsAnalysis ( ) or
22
- this = TValueFlowAnalysis ( )
23
- }
24
-
19
+ abstract class BufferWriteEstimationReason extends TBufferWriteEstimationReason {
25
20
/**
26
21
* Returns a human readable representation of this reason
27
22
*/
28
- string toString ( ) {
29
- this = TTypeBoundsAnalysis ( ) and result = "based on type bounds"
30
- or
31
- this = TValueFlowAnalysis ( ) and result = "based on flow analysis of value bounds"
32
- }
23
+ abstract string toString ( ) ;
33
24
34
25
/**
35
26
* Combine estimate reasons. Used to give a reason for the size of a format string
36
27
* conversion given reasons coming from its individual specifiers
37
28
*/
38
- BufferWriteEstimationReason combineWith ( BufferWriteEstimationReason other ) {
39
- ( this = TTypeBoundsAnalysis ( ) or other = TTypeBoundsAnalysis ( ) ) and
40
- result = TTypeBoundsAnalysis ( )
41
- or
42
- ( this = TValueFlowAnalysis ( ) and other = TValueFlowAnalysis ( ) ) and
43
- result = TValueFlowAnalysis ( )
44
- }
29
+ abstract BufferWriteEstimationReason combineWith ( BufferWriteEstimationReason other ) ;
45
30
}
46
31
47
32
/**
48
33
* The estimation comes from rough bounds just based on the type (e.g.
49
34
* `0 <= x < 2^32` for an unsigned 32 bit integer)
50
35
*/
51
- BufferWriteEstimationReason typeBoundsAnalysis ( ) { result = TTypeBoundsAnalysis ( ) }
36
+ class TypeBoundsAnalysis extends BufferWriteEstimationReason , TTypeBoundsAnalysis {
37
+ override string toString ( ) { result = "based on type bounds" }
38
+
39
+ override BufferWriteEstimationReason combineWith ( BufferWriteEstimationReason other ) {
40
+ result = TTypeBoundsAnalysis ( ) and other = other
41
+ }
42
+ }
52
43
53
44
/**
54
45
* The estimation comes from non trivial bounds found via actual flow analysis.
@@ -60,7 +51,14 @@ BufferWriteEstimationReason typeBoundsAnalysis() { result = TTypeBoundsAnalysis(
60
51
* }
61
52
* ```
62
53
*/
63
- BufferWriteEstimationReason valueFlowAnalysis ( ) { result = TValueFlowAnalysis ( ) }
54
+ class ValueFlowAnalysis extends BufferWriteEstimationReason , TValueFlowAnalysis {
55
+ override string toString ( ) { result = "based on flow analysis of value bounds" }
56
+
57
+ override BufferWriteEstimationReason combineWith ( BufferWriteEstimationReason other ) {
58
+ other = TTypeBoundsAnalysis ( ) and result = TTypeBoundsAnalysis ( ) or
59
+ other = TValueFlowAnalysis ( ) and result = TValueFlowAnalysis ( )
60
+ }
61
+ }
64
62
65
63
class PrintfFormatAttribute extends FormatAttribute {
66
64
PrintfFormatAttribute ( ) { this .getArchetype ( ) = [ "printf" , "__printf__" ] }
@@ -1043,7 +1041,7 @@ class FormatLiteral extends Literal {
1043
1041
* conversion specifier of this format string; has no result if this cannot
1044
1042
* be determined.
1045
1043
*/
1046
- int getMaxConvertedLength ( int n ) { result = max ( int l | l = getMaxConvertedLength ( n , _) | l ) }
1044
+ int getMaxConvertedLength ( int n ) { result = max ( getMaxConvertedLength ( n , _) ) }
1047
1045
1048
1046
/**
1049
1047
* Gets the maximum length of the string that can be produced by the nth
@@ -1263,9 +1261,7 @@ class FormatLiteral extends Literal {
1263
1261
* determining whether a buffer overflow is caused by long float to string
1264
1262
* conversions.
1265
1263
*/
1266
- int getMaxConvertedLengthLimited ( int n ) {
1267
- result = max ( int l | l = getMaxConvertedLengthLimited ( n , _) | l )
1268
- }
1264
+ int getMaxConvertedLengthLimited ( int n ) { result = max ( getMaxConvertedLengthLimited ( n , _) ) }
1269
1265
1270
1266
/**
1271
1267
* Gets the maximum length of the string that can be produced by the nth
0 commit comments