Skip to content

Commit 0f2139f

Browse files
committed
Fix and document one-based argument indexing in StringFormat's getAnArgUsageOffset
1 parent 55c72ce commit 0f2139f

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

java/ql/src/semmle/code/java/StringFormat.qll

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ class FormatString extends string {
368368
/*abstract*/ int getASkippedFmtSpecIndex() { none() }
369369

370370
/**
371-
* Gets an offset in this format string where argument `argNo` will be interpolated, if any.
371+
* Gets an offset (zero-based) in this format string where argument `argNo` (1-based) will be interpolated, if any.
372372
*/
373373
int getAnArgUsageOffset(int argNo) { none() }
374374
}
@@ -451,7 +451,6 @@ private class PrintfFormatString extends FormatString {
451451
override int getAnArgUsageOffset(int argNo) {
452452
argNo = fmtSpecRefersToSpecificIndex(result)
453453
or
454-
fmtSpecRefersToSequentialIndex(result) and
455454
result = rank[argNo](int i | fmtSpecRefersToSequentialIndex(i))
456455
or
457456
fmtSpecRefersToPrevious(result) and
@@ -485,8 +484,5 @@ private class LoggerFormatString extends FormatString {
485484

486485
override int getMaxFmtSpecIndex() { result = count(int i | fmtPlaceholder(i)) }
487486

488-
override int getAnArgUsageOffset(int argNo) {
489-
fmtPlaceholder(result) and
490-
argNo = count(int i | fmtPlaceholder(i) and i < result)
491-
}
487+
override int getAnArgUsageOffset(int argNo) { result = rank[argNo](int i | fmtPlaceholder(i)) }
492488
}

0 commit comments

Comments
 (0)