-
-
Save rightfold/203a80bbe1bacd9f41b8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
case class PrintfCall(format: String, arguments: Seq[Expression]) extends Expression { | |
def sanitized(implicit sink: DiagnosticSink): PrintfCall = { | |
if ("""%[^diouxxcs%]""".r.findAllIn(format + "\0").isEmpty) { | |
val count = """%[diouxxcs]""".r.findAllIn(format).size | |
if (arguments.size < count) sink.error("not enough arguments to printf") | |
if (arguments.size > count) sink.warning("too many arguments to printf") | |
} else { | |
sink.error(s"illegal or unfinished conversion specifier inside format string") | |
} | |
this | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment