aboutsummaryrefslogtreecommitdiff
path: root/contrib/file/src/vasprintf.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/file/src/vasprintf.c')
-rw-r--r--contrib/file/src/vasprintf.c19
1 files changed, 8 insertions, 11 deletions
diff --git a/contrib/file/src/vasprintf.c b/contrib/file/src/vasprintf.c
index 49d33d4a4ac2..940e8a4a3630 100644
--- a/contrib/file/src/vasprintf.c
+++ b/contrib/file/src/vasprintf.c
@@ -108,7 +108,7 @@ you use strange formats.
#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: vasprintf.c,v 1.17 2019/11/15 21:03:14 christos Exp $")
+FILE_RCSID("@(#)$File: vasprintf.c,v 1.23 2022/09/24 20:30:13 christos Exp $")
#endif /* lint */
#include <assert.h>
@@ -131,7 +131,7 @@ FILE_RCSID("@(#)$File: vasprintf.c,v 1.17 2019/11/15 21:03:14 christos Exp $")
* structure, which is passed among nearly every sub-functions.
*/
typedef struct {
- const char * src_string; /* current position into intput string */
+ const char * src_string; /* current position into input string */
char * buffer_base; /* output buffer */
char * dest_string; /* current position into output string */
size_t buffer_len; /* length of output buffer */
@@ -139,14 +139,12 @@ typedef struct {
size_t pseudo_len; /* total length of output text if it were not limited in size */
size_t maxlen;
va_list vargs; /* pointer to current position into vargs */
- char * sprintf_string;
- FILE * fprintf_file;
} xprintf_struct;
/*
* Realloc buffer if needed
* Return value: 0 = ok
- * EOF = not enought memory
+ * EOF = not enough memory
*/
static int realloc_buff(xprintf_struct *s, size_t len)
{
@@ -178,7 +176,7 @@ static int usual_char(xprintf_struct * s)
{
size_t len;
- len = strcspn(s->src_string, "%"); /* reachs the next '%' or end of input string */
+ len = strcspn(s->src_string, "%"); /* reaches the next '%' or end of input string */
/* note: 'len' is never 0 because the presence of '%' */
/* or end-of-line is checked in the calling function */
@@ -245,7 +243,7 @@ static int type_s(xprintf_struct *s, int width, int prec,
if (arg_string == NULL)
return print_it(s, (size_t)6, "(null)", 0);
- /* hand-made strlen() whitch stops when 'prec' is reached. */
+ /* hand-made strlen() which stops when 'prec' is reached. */
/* if 'prec' is -1 then it is never reached. */
string_len = 0;
while (arg_string[string_len] != 0 && (size_t)prec != string_len)
@@ -258,7 +256,7 @@ static int type_s(xprintf_struct *s, int width, int prec,
}
/*
- * Read a serie of digits. Stop when non-digit is found.
+ * Read a series of digits. Stop when non-digit is found.
* Return value: the value read (between 0 and 32767).
* Note: no checks are made against overflow. If the string contain a big
* number, then the return value won't be what we want (but, in this case,
@@ -595,8 +593,6 @@ static int core(xprintf_struct *s)
}
/* for (v)asnprintf */
- dummy_base = s->buffer_base;
-
dummy_base = s->buffer_base + s->real_len;
save_len = s->real_len;
@@ -625,6 +621,7 @@ int vasprintf(char **ptr, const char *format_string, va_list vargs)
xprintf_struct s;
int retval;
+ memset(&s, 0, sizeof(s));
s.src_string = format_string;
#ifdef va_copy
va_copy (s.vargs, vargs);
@@ -635,7 +632,7 @@ int vasprintf(char **ptr, const char *format_string, va_list vargs)
# ifdef WIN32
s.vargs = vargs;
# else
- memcpy (&s.vargs, &vargs, sizeof (s.va_args));
+ memcpy (&s.vargs, &vargs, sizeof (s.vargs));
# endif /* WIN32 */
# endif /* __va_copy */
#endif /* va_copy */