@@ -16,39 +16,30 @@ private newtype TBufferWriteEstimationReason =
1616/**
1717 * A reason for a specific buffer write size estimate
1818 */
19- class BufferWriteEstimationReason extends TBufferWriteEstimationReason {
20- BufferWriteEstimationReason ( ) {
21- this = TTypeBoundsAnalysis ( ) or
22- this = TValueFlowAnalysis ( )
23- }
24-
19+ abstract class BufferWriteEstimationReason extends TBufferWriteEstimationReason {
2520 /**
2621 * Returns a human readable representation of this reason
2722 */
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 ( ) ;
3324
3425 /**
3526 * Combine estimate reasons. Used to give a reason for the size of a format string
3627 * conversion given reasons coming from its individual specifiers
3728 */
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 ) ;
4530}
4631
4732/**
4833 * The estimation comes from rough bounds just based on the type (e.g.
4934 * `0 <= x < 2^32` for an unsigned 32 bit integer)
5035 */
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+ }
5243
5344/**
5445 * The estimation comes from non trivial bounds found via actual flow analysis.
@@ -60,7 +51,14 @@ BufferWriteEstimationReason typeBoundsAnalysis() { result = TTypeBoundsAnalysis(
6051 * }
6152 * ```
6253 */
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+ }
6462
6563class PrintfFormatAttribute extends FormatAttribute {
6664 PrintfFormatAttribute ( ) { this .getArchetype ( ) = [ "printf" , "__printf__" ] }
@@ -1043,7 +1041,7 @@ class FormatLiteral extends Literal {
10431041 * conversion specifier of this format string; has no result if this cannot
10441042 * be determined.
10451043 */
1046- int getMaxConvertedLength ( int n ) { result = max ( int l | l = getMaxConvertedLength ( n , _) | l ) }
1044+ int getMaxConvertedLength ( int n ) { result = max ( getMaxConvertedLength ( n , _) ) }
10471045
10481046 /**
10491047 * Gets the maximum length of the string that can be produced by the nth
@@ -1263,9 +1261,7 @@ class FormatLiteral extends Literal {
12631261 * determining whether a buffer overflow is caused by long float to string
12641262 * conversions.
12651263 */
1266- int getMaxConvertedLengthLimited ( int n ) {
1267- result = max ( int l | l = getMaxConvertedLengthLimited ( n , _) | l )
1268- }
1264+ int getMaxConvertedLengthLimited ( int n ) { result = max ( getMaxConvertedLengthLimited ( n , _) ) }
12691265
12701266 /**
12711267 * Gets the maximum length of the string that can be produced by the nth
0 commit comments