Re: [RFC] Some useless cleanup

Paul P Komkoff Jr (i@stingr.net)
Thu, 9 May 2002 15:33:46 +0400


Replying to Denis Vlasenko:
> Well, it isn't bad, but what's the point in multiple
> set_xxxxxx(char *dst, char *src) functions?
>
> Maybe it makes more sense to have a generic macro
> which copies string into char[N] buffer, avoiding overflow.
>

Generic plan. I has something in mind when asked, but not this ...

Actually in task_t.comm we have 2 cases
1. strncpy(a, b, sz)
2. snprintf(a, n, blah-blah...)

I thought somebody will beat me for completely eliminating strcpyn and
replacing it with snprintf in ALL CASES which is more expensive.

> A macro:
>
> #define STRNCPY(dst,src) \
> do { \
> /* todo: put clever check that dst is char[] here */ \
> strncpy((dst), (src), sizeof(dst)-1); \
> dst[sizeof(dst)-1] = '\0'; \
> } while(0)

Abstracting .comm access can result in, finally, replacing comm[16] with,
for example, *comm

Or if we require to do match_comm (netfilter match, connections belong to
process specified by name) job we can patchhook somewhere in set_xxx to
avoid excessive for_each_tasked strcmps.

... more?

-- 
Paul P 'Stingray' Komkoff 'Greatest' Jr // (icq)23200764 // (irc)Spacebar
  PPKJ1-RIPE // (smtp)i@stingr.net // (http)stingr.net // (pgp)0xA4B4ECA4
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/