@@ -42,6 +42,18 @@ private Type getAFormatterWideTypeOrDefault() {
4242 * A standard library function that uses a `printf`-like formatting string.
4343 */
4444abstract class FormattingFunction extends ArrayFunction , TaintFunction {
45+ int firstFormatArgumentIndex ;
46+
47+ FormattingFunction ( ) {
48+ firstFormatArgumentIndex > 0 and
49+ if this .hasDefinition ( )
50+ then firstFormatArgumentIndex = this .getDefinition ( ) .getNumberOfParameters ( )
51+ else
52+ forex ( FunctionDeclarationEntry fde | fde = this .getAnExplicitDeclarationEntry ( ) |
53+ firstFormatArgumentIndex = fde .getNumberOfParameters ( )
54+ )
55+ }
56+
4557 /** Gets the position at which the format parameter occurs. */
4658 abstract int getFormatParameterIndex ( ) ;
4759
@@ -121,34 +133,7 @@ abstract class FormattingFunction extends ArrayFunction, TaintFunction {
121133 * the first format specifier in the format string. We ignore all
122134 * implicit function definitions.
123135 */
124- int getFirstFormatArgumentIndex ( ) {
125- // The formatting function either has a definition in the snapshot, or all
126- // `DeclarationEntry`s agree on the number of parameters (otherwise we don't
127- // really know the correct number)
128- result > 0 and // Avoid invalid declarations
129- if this .hasDefinition ( )
130- then result = this .getDefinition ( ) .getNumberOfParameters ( )
131- else result = this .getNumberOfExplicitParameters ( )
132- }
133-
134- /**
135- * Gets a non-implicit function declaration entry.
136- */
137- private FunctionDeclarationEntry getAnExplicitDeclarationEntry ( ) {
138- result = this .getADeclarationEntry ( ) and
139- not result .isImplicit ( )
140- }
141-
142- /**
143- * Gets the number of parameters, excluding any parameters that have been defined
144- * from implicit function declarations. If there is some inconsistency in the number
145- * of parameters, then don't return anything.
146- */
147- int getNumberOfExplicitParameters ( ) {
148- forex ( FunctionDeclarationEntry fde | fde = this .getAnExplicitDeclarationEntry ( ) |
149- result = fde .getNumberOfParameters ( )
150- )
151- }
136+ int getFirstFormatArgumentIndex ( ) { result = firstFormatArgumentIndex }
152137
153138 /**
154139 * Gets the position of the buffer size argument, if any.
0 commit comments