Re: [PATCH 2/3] string: provide strscpy() and strscpy_truncate()

2015-05-07 Thread Chris Metcalf
On 05/07/2015 05:00 AM, Dan Carpenter wrote: On Wed, May 06, 2015 at 06:45:56PM +0200, Geert Uytterhoeven wrote: On Wed, May 6, 2015 at 5:59 PM, Dan Carpenter wrote: We actually do have a __must_check tag so it's easy enough to force people to check. A different option is we could make it

Re: [PATCH 2/3] string: provide strscpy() and strscpy_truncate()

2015-05-07 Thread Dan Carpenter
On Wed, May 06, 2015 at 06:45:56PM +0200, Geert Uytterhoeven wrote: > On Wed, May 6, 2015 at 5:59 PM, Dan Carpenter > wrote: > > We actually do have a __must_check tag so it's easy enough to force > > people to check. A different option is we could make it trigger a > > People tend to ignore

Re: [PATCH 2/3] string: provide strscpy() and strscpy_truncate()

2015-05-07 Thread Dan Carpenter
On Wed, May 06, 2015 at 06:45:56PM +0200, Geert Uytterhoeven wrote: On Wed, May 6, 2015 at 5:59 PM, Dan Carpenter dan.carpen...@oracle.com wrote: We actually do have a __must_check tag so it's easy enough to force people to check. A different option is we could make it trigger a People

Re: [PATCH 2/3] string: provide strscpy() and strscpy_truncate()

2015-05-07 Thread Chris Metcalf
On 05/07/2015 05:00 AM, Dan Carpenter wrote: On Wed, May 06, 2015 at 06:45:56PM +0200, Geert Uytterhoeven wrote: On Wed, May 6, 2015 at 5:59 PM, Dan Carpenter dan.carpen...@oracle.com wrote: We actually do have a __must_check tag so it's easy enough to force people to check. A different

Re: [PATCH 2/3] string: provide strscpy() and strscpy_truncate()

2015-05-06 Thread Geert Uytterhoeven
On Wed, May 6, 2015 at 5:59 PM, Dan Carpenter wrote: > We actually do have a __must_check tag so it's easy enough to force > people to check. A different option is we could make it trigger a People tend to ignore compiler warnings... > WARN_ONCE(). > > #define strXcpy(dest, src, len) (({

Re: [PATCH 2/3] string: provide strscpy() and strscpy_truncate()

2015-05-06 Thread Dan Carpenter
We actually do have a __must_check tag so it's easy enough to force people to check. A different option is we could make it trigger a WARN_ONCE(). #define strXcpy(dest, src, len) (({ \ ssize_t __ret = strscpy_truncate(dest, src, len); \

Re: [PATCH 2/3] string: provide strscpy() and strscpy_truncate()

2015-05-06 Thread Chris Metcalf
On 5/6/2015 11:01 AM, Dan Carpenter wrote: On Thu, Apr 30, 2015 at 12:01:16PM -0400, Chris Metcalf wrote: >+ssize_t strscpy(char *dest, const char *src, size_t count) >+{ >+ ssize_t res = strscpy_truncate(dest, src, count); >+ if (res < 0 && count != 0) >+ dest[0] = '\0'; How is

Re: [PATCH 2/3] string: provide strscpy() and strscpy_truncate()

2015-05-06 Thread Dan Carpenter
On Thu, Apr 30, 2015 at 12:01:16PM -0400, Chris Metcalf wrote: > +ssize_t strscpy(char *dest, const char *src, size_t count) > +{ > + ssize_t res = strscpy_truncate(dest, src, count); > + if (res < 0 && count != 0) > + dest[0] = '\0'; How is this better than returning a

Re: [PATCH 2/3] string: provide strscpy() and strscpy_truncate()

2015-05-06 Thread Geert Uytterhoeven
On Wed, May 6, 2015 at 5:59 PM, Dan Carpenter dan.carpen...@oracle.com wrote: We actually do have a __must_check tag so it's easy enough to force people to check. A different option is we could make it trigger a People tend to ignore compiler warnings... WARN_ONCE(). #define strXcpy(dest,

Re: [PATCH 2/3] string: provide strscpy() and strscpy_truncate()

2015-05-06 Thread Chris Metcalf
On 5/6/2015 11:01 AM, Dan Carpenter wrote: On Thu, Apr 30, 2015 at 12:01:16PM -0400, Chris Metcalf wrote: +ssize_t strscpy(char *dest, const char *src, size_t count) +{ + ssize_t res = strscpy_truncate(dest, src, count); + if (res 0 count != 0) + dest[0] = '\0'; How is this

Re: [PATCH 2/3] string: provide strscpy() and strscpy_truncate()

2015-05-06 Thread Dan Carpenter
On Thu, Apr 30, 2015 at 12:01:16PM -0400, Chris Metcalf wrote: +ssize_t strscpy(char *dest, const char *src, size_t count) +{ + ssize_t res = strscpy_truncate(dest, src, count); + if (res 0 count != 0) + dest[0] = '\0'; How is this better than returning a truncated

Re: [PATCH 2/3] string: provide strscpy() and strscpy_truncate()

2015-05-06 Thread Dan Carpenter
We actually do have a __must_check tag so it's easy enough to force people to check. A different option is we could make it trigger a WARN_ONCE(). #define strXcpy(dest, src, len) (({ \ ssize_t __ret = strscpy_truncate(dest, src, len); \

[PATCH 2/3] string: provide strscpy() and strscpy_truncate()

2015-04-30 Thread Chris Metcalf
The strscpy() API is intended to be used instead of strlcpy(), and instead of most uses of strncpy(). - The API provides an easy way to check for destination buffer overflow: a -E2BIG error return value. - By default, truncation causes the destination buffer to be the empty string, so users

[PATCH 2/3] string: provide strscpy() and strscpy_truncate()

2015-04-30 Thread Chris Metcalf
The strscpy() API is intended to be used instead of strlcpy(), and instead of most uses of strncpy(). - The API provides an easy way to check for destination buffer overflow: a -E2BIG error return value. - By default, truncation causes the destination buffer to be the empty string, so users