- while (1)
- {
- /* The GNU coding standards advise not to rely on the return
- value of sprintf(). However, vsnprintf() is a relatively
- new function missing from legacy systems. Therefore it's
- safe to assume that its return value is meaningful. On
- the systems where vsnprintf() is not available, we use
- the implementation from snprintf.c which does return the
- correct value. */
- int numwritten = vsnprintf (write_ptr, available_size, fmt, args);
-
- /* vsnprintf() will not step over the limit given by
- available_size. If it fails, it will return either -1
- (POSIX?) or the number of characters that *would have*
- been written, if there had been enough room. In the
- former case, we double the available_size and malloc() to
- get a larger buffer, and try again. In the latter case,
- we use the returned information to build a buffer of the
- correct size. */
-
- if (numwritten == -1)
- {
- /* Writing failed, and we don't know the needed size.
- Try again with doubled size. */
- available_size <<= 1;
- bigmsg = xrealloc (bigmsg, available_size);
- write_ptr = bigmsg;
- }
- else if (numwritten >= available_size)
- {
- /* Writing failed, but we know exactly how much space we
- need. */
- available_size = numwritten + 1;
- bigmsg = xrealloc (bigmsg, available_size);
- write_ptr = bigmsg;
- }
- else
- {
- /* Writing succeeded. */
- break;
- }
- }
- saved_append (write_ptr);
- fputs (write_ptr, logfp);
- if (bigmsg)
- xfree (bigmsg);
+ /* The GNU coding standards advise not to rely on the return value
+ of sprintf(). However, vsnprintf() is a relatively new function
+ missing from legacy systems. Therefore I consider it safe to
+ assume that its return value is meaningful. On the systems where
+ vsnprintf() is not available, we use the implementation from
+ snprintf.c which does return the correct value. */
+ numwritten = vsnprintf (write_ptr, available_size, fmt, args);
+
+ /* vsnprintf() will not step over the limit given by available_size.
+ If it fails, it will return either -1 (POSIX?) or the number of
+ characters that *would have* been written, if there had been
+ enough room. In the former case, we double the available_size
+ and malloc() to get a larger buffer, and try again. In the
+ latter case, we use the returned information to build a buffer of
+ the correct size. */
+
+ if (numwritten == -1)
+ {
+ /* Writing failed, and we don't know the needed size. Try
+ again with doubled size. */
+ int newsize = available_size << 1;
+ state->bigmsg = xrealloc (state->bigmsg, newsize);
+ state->allocated = newsize;
+ return 0;