NetBSD-Bugs archive

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

Re: PR/47577 CVS commit: src/usr.bin/mail



The following reply was made to PR bin/47577; it has been noted by GNATS.

From: Steffen "Daode" Nurpmeso <sdaoden%gmail.com@localhost>
To: gnats-admin%netbsd.org@localhost, gnats-bugs%NetBSD.org@localhost,
 netbsd-bugs%netbsd.org@localhost
Cc: 
Subject: Re: PR/47577 CVS commit: src/usr.bin/mail
Date: Mon, 25 Feb 2013 20:06:08 +0100

 ..This may also be sufficient.
 (Just scream, i'll stop, then ...)
 
 --steffen
 
 diff -Napru mail.orig/lex.c mail/lex.c
 --- mail.orig/lex.c    2013-02-25 14:58:37.000000000 +0100
 +++ mail/lex.c 2013-02-25 20:04:28.000000000 +0100
 @@ -144,8 +144,8 @@ file_leak_check(void)
  static void
  update_mailname(const char *name)
  {
 -      char tbuf[PATHSIZE];
 -      size_t l;
 +      char tbuf[PATHSIZE], *mailp, *dispp;
 +      size_t si, i, j;
 =20
        /* Don't realpath(3) if it's only an update request */
        if (name !=3D NULL && realpath(name, mailname) =3D=3D NULL) {
 @@ -153,32 +153,37 @@ update_mailname(const char *name)
                return;
        }
 =20
 +      mailp =3D mailname;
 +      dispp =3D displayname;
 +
 +      /* Don't display an absolute path but "+FOLDER" if under *folder* */
        if (getfold(tbuf, sizeof(tbuf)) >=3D 0) {
 -              l =3D strlen(tbuf);
 -              if (l < sizeof(tbuf) - 1)
 -                      tbuf[l++] =3D '/';
 -              if (strncmp(tbuf, mailname, l) =3D=3D 0) {
 -                      char const *sep =3D "", *cp =3D mailname + l;
 -
 -                      l =3D strlen(cp);
 -                      if (l >=3D sizeof(displayname)) {
 -                              cp +=3D l;
 -                              cp -=3D sizeof(displayname) - 5;
 -                              sep =3D "...";
 -                      }
 -                      (void)snprintf(displayname, sizeof(displayname),
 -                          "+%s%s", sep, cp);
 -                      return;
 +              i =3D strlen(tbuf);
 +              if (i < sizeof(tbuf) - 1)
 +                      tbuf[i++] =3D '/';
 +              if (strncmp(tbuf, mailp, i) =3D=3D 0) {
 +                      mailp +=3D i;
 +                      *dispp++ =3D '+';
                }
        }
 =20
 -      l =3D strlen(mailname);
 -      if (l < sizeof(displayname))
 -              strcpy(displayname, mailname);
 +      /* We want to see the name of the folder .. on the screen */
 +      i =3D strlen(mailp);
 +      if (i < sizeof(displayname) - 1)
 +              memcpy(dispp, mailp, i + 1);
        else {
 -              l -=3D sizeof(displayname) - 4 - sizeof(displayname) / 3;
 -              (void)snprintf(displayname, sizeof(displayname), "%.*s...%s",
 -                      (int)sizeof(displayname) / 3, mailname, mailname + l);
 +              j =3D sizeof(displayname) / 3;
 +              si =3D i;
 +              i -=3D sizeof(displayname) - (1 /* "+" */ + 4) - j;
 +              /* Avoid disrupting multibyte sequences */
 +              goto jmblen;
 +              while (i < si && mblen(mailp + i, si - i) < 0) {
 +                      ++i;
 +jmblen:
 +                      mblen(NULL, 0);
 +              }
 +              (void)snprintf(dispp, sizeof(displayname) - 1, "%.*s...%s",
 +                      (int)j, mailp, mailp + i);
        }
  }
 =20
 


Home | Main Index | Thread Index | Old Index