Skip to content
Snippets Groups Projects
Commit ff1a27c0 authored by deuce's avatar deuce
Browse files

Remove MAX_ARG_LEN usage.

Rename entry_buf to int_buf since it only ever holds an integer now.
parent a99197da
No related branches found
No related tags found
No related merge requests found
...@@ -66,12 +66,6 @@ int asprintf(char **strptr, char *format, ...) ...@@ -66,12 +66,6 @@ int asprintf(char **strptr, char *format, ...)
} }
#endif #endif
/* MSVC Sucks - can't tell the required len of a *printf() */
#define MAX_ARG_LEN 1024 /* MAX_ARG_LEN is the maximum length
* possible as a result of a format
* which is not %s
*/
/* Maximum length of a format specifier including the % */ /* Maximum length of a format specifier including the % */
#define MAX_FORMAT_LEN 256 #define MAX_FORMAT_LEN 256
...@@ -329,7 +323,7 @@ char* DLLCALL xp_asprintf_next(char *format, int type, ...) ...@@ -329,7 +323,7 @@ char* DLLCALL xp_asprintf_next(char *format, int type, ...)
unsigned long offset2=0; unsigned long offset2=0;
size_t format_len; size_t format_len;
size_t this_format_len; size_t this_format_len;
char entry_buf[MAX_ARG_LEN]; char int_buf[MAX_FORMAT_LEN];
char *entry; char *entry;
char this_format[MAX_FORMAT_LEN]; char this_format[MAX_FORMAT_LEN];
char *fmt; char *fmt;
...@@ -388,7 +382,7 @@ char* DLLCALL xp_asprintf_next(char *format, int type, ...) ...@@ -388,7 +382,7 @@ char* DLLCALL xp_asprintf_next(char *format, int type, ...)
*/ */
if(*p=='*') { /* The argument is this width */ if(*p=='*') { /* The argument is this width */
va_start(vars, type); va_start(vars, type);
i=sprintf(entry_buf,"%d", va_arg(vars, int)); i=sprintf(int_buf,"%d", va_arg(vars, int));
va_end(vars); va_end(vars);
if(i > 1) { if(i > 1) {
/* /*
...@@ -406,11 +400,11 @@ char* DLLCALL xp_asprintf_next(char *format, int type, ...) ...@@ -406,11 +400,11 @@ char* DLLCALL xp_asprintf_next(char *format, int type, ...)
* is so it can be overwritten * is so it can be overwritten
*/ */
memmove(p+i, p+1, format-p+format_len); memmove(p+i, p+1, format-p+format_len);
memcpy(p, entry_buf, i); memcpy(p, int_buf, i);
*(size_t *)(format+sizeof(size_t))+=i-1; *(size_t *)(format+sizeof(size_t))+=i-1;
} }
else else
*p=entry_buf[0]; *p=int_buf[0];
p=format+offset; p=format+offset;
*(size_t *)format=p-format; *(size_t *)format=p-format;
return(format); return(format);
...@@ -429,7 +423,7 @@ char* DLLCALL xp_asprintf_next(char *format, int type, ...) ...@@ -429,7 +423,7 @@ char* DLLCALL xp_asprintf_next(char *format, int type, ...)
*/ */
if(*p=='*') { if(*p=='*') {
va_start(vars, type); va_start(vars, type);
i=sprintf(entry_buf,"%d", va_arg(vars, int)); i=sprintf(int_buf,"%d", va_arg(vars, int));
va_end(vars); va_end(vars);
if(i > 1) { if(i > 1) {
/* /*
...@@ -447,11 +441,11 @@ char* DLLCALL xp_asprintf_next(char *format, int type, ...) ...@@ -447,11 +441,11 @@ char* DLLCALL xp_asprintf_next(char *format, int type, ...)
* is so it can be overwritten * is so it can be overwritten
*/ */
memmove(p+i, p+1, format-p+format_len); memmove(p+i, p+1, format-p+format_len);
memcpy(p, entry_buf, i); memcpy(p, int_buf, i);
*(size_t *)(format+sizeof(size_t))+=i-1; *(size_t *)(format+sizeof(size_t))+=i-1;
} }
else else
*p=entry_buf[0]; *p=int_buf[0];
p=format+offset; p=format+offset;
*(size_t *)format=p-format; *(size_t *)format=p-format;
return(format); return(format);
...@@ -1205,18 +1199,8 @@ char* DLLCALL xp_asprintf_next(char *format, int type, ...) ...@@ -1205,18 +1199,8 @@ char* DLLCALL xp_asprintf_next(char *format, int type, ...)
case XP_PRINTF_TYPE_CHARP: case XP_PRINTF_TYPE_CHARP:
if(cp==NULL) if(cp==NULL)
j=asprintf(&entry, this_format, "<null>"); j=asprintf(&entry, this_format, "<null>");
else { else
/*s=strlen(cp);
if(s<width)
s=width;
if(s<precision)
s=precision;
if(s>=MAX_ARG_LEN)
entry=(char *)alloca(s+1);
if(entry==NULL)
return(NULL);*/
j=asprintf(&entry, this_format, cp); j=asprintf(&entry, this_format, cp);
}
break; break;
case XP_PRINTF_TYPE_DOUBLE: case XP_PRINTF_TYPE_DOUBLE:
j=asprintf(&entry, this_format, d); j=asprintf(&entry, this_format, d);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment