H. Peter Anvin wrote:As I understand it, please correct me if I'm wrong: Of the three variants: strcpy, strncpy and strlcpy. - strcpy does not append \0 (unless the source string already contained it) - strncpy appends \0's if the source string is smaller than the size parameter (for all remaining characters) - strlcpy always appends a single \0 (unless size parameter was 0) char *strcpy(char *dest, const char *src); char *strncpy(char *dest, const char *src, size_t n); size_t strlcpy(char *dst, const char *src, size_t n); In the original code strncpy was used and the size parameter was equal to the source string size: strncpy(dev->dev.bus_id, info->name, sizeof(dev->dev.bus_id)); Since this the size was equal there was no \0 termination. To \0 terminate using strncpy we could write: strncpy(dev->dev.bus_id, info->name, sizeof(dev->dev.bus_id) - 1); dev->dev.bus_id[sizeof(dev->dev.bus_id) - 1] = '\0'; or using strlcpy, which does the same thing: strlcpy(dev->dev.bus_id, info->name, sizeof(dev->dev.bus_id)); Roel --
| Adrian Bunk | If you want me to quit I will quit |
| Marc Perkel | AMD Quad Core clock problem? |
| Fred Tyler | Slow, persistent memory leak in 2.6.20 |
| Rafał Bilski | Re: cpufreq longhaul locks up |
git: | |
| Pietro Mascagni | GIT vs Other: Need argument |
| Jon Smirl | ! [rejected] master -> master (non-fast forward) |
| Theodore Tso | Re: Git/Mercurial interoperability (and what about bzr?) (was: Re: [VOTE] git vers... |
| cte | linking libgit.a in C++ projects |
| qw er | OpenBSD sucks |
| GVG GVG | ssh_exchange_identification: Connection closed by remote host |
| Andrei Pirvan | apache 1.3.29 + PHP 5.2.6 on OpenBSD 4.4 |
| STeve Andre' | Re: Perpetually Current |
| Johann Baudy | Packet mmap: TX RING and zero copy |
| Herbert Xu | Re: [PATCH] pkt_sched: Destroy gen estimators under rtnl_lock(). |
| PJ Waskiewicz | [ANNOUNCE] ixgbe: Data Center Bridging (DCB) support for ixgbe |
| Matt Mackall | [PATCH] Stop scaring users with "treason uncloaked!" |
