Skip to content

Instantly share code, notes, and snippets.

@gdamore
Created May 13, 2014 00:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gdamore/33cf6c330f3248314fe3 to your computer and use it in GitHub Desktop.
Save gdamore/33cf6c330f3248314fe3 to your computer and use it in GitHub Desktop.
mixed n$ crap
diff --git a/usr/src/cmd/printf/printf.c b/usr/src/cmd/printf/printf.c
index fe1bb1b..bf07982 100644
--- a/usr/src/cmd/printf/printf.c
+++ b/usr/src/cmd/printf/printf.c
@@ -224,12 +224,19 @@ doformat(char *fmt, int *rval)
l = strspn(fmt, digits);
if ((l > 0) && (fmt[l] == '$')) {
int idx = atoi(fmt);
+ if (fargv == NULL) {
+ warnx1(_("incomplete use of n$"), NULL, NULL);
+ return (NULL);
+ }
if (idx <= myargc) {
gargv = &myargv[idx - 1];
} else {
gargv = &myargv[myargc];
}
fmt += l + 1;
+ } else if (fargv != NULL) {
+ warnx1(_("incomplete use of n$"), NULL, NULL);
+ return (NULL);
}
if (getint(&fieldwidth))
@@ -262,12 +269,20 @@ doformat(char *fmt, int *rval)
l = strspn(fmt, digits);
if ((l > 0) && (fmt[l] == '$')) {
int idx = atoi(fmt);
+ if (fargv == NULL) {
+ warnx1(_("incomplete use of n$"),
+ NULL, NULL);
+ return (NULL);
+ }
if (idx <= myargc) {
gargv = &myargv[idx - 1];
} else {
gargv = &myargv[myargc];
}
fmt += l + 1;
+ } else if (fargv != NULL) {
+ warnx1(_("incomplete use of n$"), NULL, NULL);
+ return (NULL);
}
if (getint(&precision))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment