pan-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Pan-devel] bug in uulib/fptools.c + patch


From: Charles Kerr
Subject: Re: [Pan-devel] bug in uulib/fptools.c + patch
Date: Sat, 13 May 2006 07:54:19 -0500 (CDT)
User-agent: SquirrelMail/1.4.6 [CVS]

> Hello,
>
> The optimization (wrt. the original uulib) of _FP_fgets function in
> uulib/fptools.c introduced a quite serious bug. The last character of
> long lines gets overwritten. Whan parsing headers the library
> introduces spurious file, when its length is multiple of 254.
>
> I've noticed this, when some of the attachements didn't get saved
> without any message. BTW, it would be good if some kind of error
> message was printed in task-article.cc:on_finished when item->state is
> not UUFILE_OK.
>
> Attached is a patch which fixes this problem.
>
> Regards,
> Jarek

I've applied the idea of this patch to a couple of other
fixes that I found with valgrind in _FP_fgets this week.
What do you think of:

char * TOOLEXPORT
_FP_fgets (char *buf, int n, FILE *stream)
{
  *buf = '\0';
  if (!fgets (buf, n, stream))
    return NULL;

  assert (*buf);
  const int len = strlen (buf);
  char * pch = buf + len - 1;
  if (*pch != '\n') // EOF.  Ensure we end with a LF
    memcpy (pch, "\n", 2);
  else if ((pch!=buf) && (pch[-1] == '\r')) // strip CR from CRLF
    memcpy (pch-1, "\n", 2);
  buf[n-1] = '\0'; // ensure zero termination

  // if a line break is coming up, eat it
  if (len == n - 1) {
    int c = fgetc (stream);
    if (c == '\r')
      c = fgetc (stream);
    if (c != '\n')
      ungetc (c, stream);
  }

  return buf;
}






reply via email to

[Prev in Thread] Current Thread [Next in Thread]