Re: sysctl warns6 cleanup

看板DFBSD_submit作者時間21年前 (2005/01/09 03:32), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串2/10 (看更多)
On Sat, Jan 08, 2005 at 05:17:17PM +0100, Peter Schuller wrote: > @@ -518,20 +519,20 @@ > case 'A': > if (!nflag) > printf("%s%s", name, sep); > - printf("%.*s", len, p); > + printf("%.*s", (int)len, p); > return (0); > There should be at least a check for the value of len, to ensure that it actually fits into an int. > case 'I': > if (!nflag) > printf("%s%s", name, sep); > fmt++; > - val = ""; > + strcpy(val, ""); > while (len >= sizeof(int)) { > if(*fmt == 'U') > printf("%s%u", val, *(unsigned int *)p); > else > printf("%s%d", val, *(int *)p); > - val = " "; > + strcpy(val, " "); > len -= sizeof(int); > p += sizeof(int); > } Dont do this, please. Use a new variable or reuse sep, this are constant strings and should stay so. [for cases of the above] > @@ -644,7 +645,7 @@ > > l2 /= sizeof(int); > > - if (l2 < len) > + if (l2 < (size_t)len) > return 0; > > for (i = 0; i < len; i++) Change oidfmt and sysctl_all to take the lenght as size_t instead. Joerg
文章代碼(AID): #11u3K-00 (DFBSD_submit)
討論串 (同標題文章)
文章代碼(AID): #11u3K-00 (DFBSD_submit)