diff --git a/include/rua_internal.h b/include/rua_internal.h index a41177bae..955e6d5e6 100644 --- a/include/rua_internal.h +++ b/include/rua_internal.h @@ -52,7 +52,9 @@ void RUA_String_Init (struct progs_s *pr, int secure); void RUA_QFile_Init (struct progs_s *pr, int secure); void RUA_QFS_Init (struct progs_s *pr, int secure); -void RUA_Sprintf (struct progs_s *pr, struct dstring_s *dstr); +// the variable args are assumed to come immediately after fmt_arg +void RUA_Sprintf (struct progs_s *pr, struct dstring_s *dstr, const char *func, + int fmt_arg); int QFile_AllocHandle (struct progs_s *pr, QFile *file); QFile *QFile_GetFile (struct progs_s *pr, int handle); diff --git a/libs/ruamoko/rua_string.c b/libs/ruamoko/rua_string.c index 314c6d099..f5ccd6d86 100644 --- a/libs/ruamoko/rua_string.c +++ b/libs/ruamoko/rua_string.c @@ -61,14 +61,14 @@ bi_strlen (progs_t *pr) } void -RUA_Sprintf (progs_t *pr, dstring_t *dstr) +RUA_Sprintf (progs_t *pr, dstring_t *dstr, const char *func, int fmt_arg) { - const char *fmt = P_GSTRING (pr, 0); - int count = pr->pr_argc - 1; - pr_type_t **args = pr->pr_params + 1; + const char *fmt = P_GSTRING (pr, fmt_arg); + int count = pr->pr_argc - (fmt_arg + 1); + pr_type_t **args = pr->pr_params + (fmt_arg + 1); if (pr->progs->version == PROG_VERSION) { - __auto_type va_list = &P_PACKED (pr, pr_va_list_t, 1); + __auto_type va_list = &P_PACKED (pr, pr_va_list_t, (fmt_arg + 1)); count = va_list->count; if (count) { args = alloca (count * sizeof (pr_type_t *)); @@ -80,7 +80,7 @@ RUA_Sprintf (progs_t *pr, dstring_t *dstr) } } - PR_Sprintf (pr, dstr, "bi_sprintf", fmt, count, args); + PR_Sprintf (pr, dstr, func, fmt, count, args); } static void @@ -89,7 +89,7 @@ bi_sprintf (progs_t *pr) dstring_t *dstr; dstr = dstring_newstr (); - RUA_Sprintf (pr, dstr); + RUA_Sprintf (pr, dstr, "sprintf", 0); RETURN_STRING (pr, dstr->str); dstring_delete (dstr); } diff --git a/ruamoko/qwaq/builtins/main.c b/ruamoko/qwaq/builtins/main.c index 3a0561035..9bb4d838f 100644 --- a/ruamoko/qwaq/builtins/main.c +++ b/ruamoko/qwaq/builtins/main.c @@ -150,7 +150,7 @@ bi_printf (progs_t *pr) { dstring_t *dstr = dstring_new (); - RUA_Sprintf (pr, dstr); + RUA_Sprintf (pr, dstr, "printf", 0); if (dstr->str) { Sys_Printf ("%s", dstr->str); } diff --git a/tools/qfcc/test/test-bi.c b/tools/qfcc/test/test-bi.c index e12220f8f..1965db082 100644 --- a/tools/qfcc/test/test-bi.c +++ b/tools/qfcc/test/test-bi.c @@ -54,7 +54,7 @@ bi_printf (progs_t *pr) dstring_clear (dstr); } - RUA_Sprintf (pr, dstr); + RUA_Sprintf (pr, dstr, "printf", 0); if (dstr->str) { fputs (dstr->str, stdout);