Mentioning strtonum(3) in style(9)

看板DFBSD_submit作者時間21年前 (2004/09/04 08:01), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/3 (看更多)
Hello There was a recent style(9) commit regarding the use of safe functions, so I guess strtonum(3) should be mentioned too. Below is a patch, though someone who speaks english better than me will probably come up with better wording... --- style.9.orig 2004-09-03 19:38:00.000000000 -0300 +++ style.9 2004-09-03 20:38:34.000000000 -0300 @@ -353,10 +353,10 @@ bflag = 1; break; case 'n': - num = strtol(optarg, &ep, 10); - if (num <= 0 || *ep != '\e0') { - warnx("illegal number, -n argument -- %s", - optarg); + num = strtonum(optarg, 0, INT_MAX, &errstr); + if (errstr) { + warnx("-n argument is %s: %s", errstr, + optarg); usage(); } break; @@ -652,6 +652,14 @@ should be used instead of .Xr sprintf 3 . .Pp +When doing string-to-number conversions, +.Xr strtonum 3 +should be used instead of functions which are either difficult or impossible +to use safely, such as +.Xr atoi 3 , +.Xr strtol 3 +and similars. +.Pp Varargs procedures should be formatted as follows: .Bd -literal #include <stdarg.h> I'd like to point to a previous thread[1] where I sent a patch to mention strtonum on the manual pages of the other string-to-number functions (as well as patches that substitute calls to these functions). Regards, Andre [1]http://leaf.dragonflybsd.org/mailarchive/submit/2004-08/msg00078.html
文章代碼(AID): #11EGN000 (DFBSD_submit)
文章代碼(AID): #11EGN000 (DFBSD_submit)