Pete Zaitcev wrote:
On Sun, 30 Jan 2005 15:28:23 +0300, Michael Tokarev <[EMAIL PROTECTED]> wrote:

We have sizeof(), don't we?  Ie, why
  snprintf(hid->name, 128, "%s", buf);
instead of
  snprintf(hid->name, sizeof(hid->name), "%s", buf);

I always fight this sort of patches, because the moment hid->name becomes a pointer (and it's almost inevitable for most structures), this scheme breaks down. The right approach is to have a symbolic constant HID_NAME_SIZE or such.

If it will become a pointer, all those snprintfs should be changed into something like asprintf() (there's no such interface in kernel but mentioning that routine is sufficient to get the "idea") -- if the buffer isn't static, direct snprintf() is not appropriate in most cases, you have to "realloc" it when changing the content. Unless, ofcourse, you'll use something like hid->name = kmalloc(HID_NAME_SIZE); which makes no real difference for static buffer vs a pointer -- ie, there's no reason to convert static buffer into a pointer to static-size storage.

/mjt


------------------------------------------------------- This SF.Net email is sponsored by: IntelliVIEW -- Interactive Reporting Tool for open source databases. Create drag-&-drop reports. Save time by over 75%! Publish reports on the web. Export to DOC, XLS, RTF, etc. Download a FREE copy at http://www.intelliview.com/go/osdn_nl _______________________________________________ linux-usb-devel@lists.sourceforge.net To unsubscribe, use the last form field at: https://lists.sourceforge.net/lists/listinfo/linux-usb-devel

Reply via email to