Skip to content

Instantly share code, notes, and snippets.

@rightfold
Last active August 29, 2015 14:17
Show Gist options
  • Save rightfold/203a80bbe1bacd9f41b8 to your computer and use it in GitHub Desktop.
Save rightfold/203a80bbe1bacd9f41b8 to your computer and use it in GitHub Desktop.
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