On 04/21/16 19:26, Alan Somers wrote:
On Thu, Apr 21, 2016 at 11:09 AM, Ngie Cooper <yaneurab...@gmail.com> wrote:

On Thu, Apr 21, 2016 at 10:08 AM, Ngie Cooper <yaneurab...@gmail.com>
wrote:
On Thu, Apr 21, 2016 at 9:43 AM, Alan Somers <asom...@freebsd.org>
  {
         struct g_geom *gp;
         struct g_provider *pp;
+       char devnamebuf[128];

Why 128? Also, why not sbuf?

         gp = dp->d_geom;
         if (gp != NULL)
                 LIST_FOREACH(pp, &gp->provider, provider)
                         (void)g_attr_changed(pp, attr, flag);
+       snprintf(devnamebuf, 128, "devname=%s%d", dp->d_name,
dp->d_unit);

Why not sizeof(devnamebuf) ?

Also: this doesn't NUL terminate devnamebuf; it really should
(otherwise, boom... crash in geom)...


snprintf(3) says "The output is always null-terminated." and it looks like
the kernel version does the same thing at subr_prf.c:560.  Am I missing
something?


Hi,

The code is correct, though it is good practice to use sizeof() like Ngie suggests or define the size of the buffer like a macro.

grep -rE "snprintf.*sizeof" /usr/src/sys/dev

--HPS
_______________________________________________
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to