Bug 143330

Summary: [patch] strtonum(3) does undocumented clobbering of errno
Product: Documentation Reporter: Efstratios Karatzas <gpf.kira> <gpf.kira>
Component: Books & ArticlesAssignee: Benedict Reuschling <bcr>
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: Latest   
Hardware: Any   
OS: Any   
Attachments:
Description Flags
file.diff none

Description Efstratios Karatzas <gpf.kira@gmail.com> 2010-01-28 22:50:11 UTC
As noted by commiter Bruce Evans in the pr trail of bin/142911,
strtonum() sets errno to 0 when no error is found.
Checked the source myself and this seems to be the case.
This behavior is undocumented.

Fix: Take a look at the patch below.
I just added this information in the "return value" 
section of the man page.
First time editing a man page, hope this is ok.

Patch attached with submission follows:
Comment 1 Benedict Reuschling freebsd_committer freebsd_triage 2010-10-08 15:17:17 UTC
Responsible Changed
From-To: freebsd-doc->bcr

I'll work on it.
Comment 2 dfilter service freebsd_committer freebsd_triage 2010-10-21 19:30:55 UTC
Author: bcr (doc committer)
Date: Thu Oct 21 18:30:48 2010
New Revision: 214148
URL: http://svn.freebsd.org/changeset/base/214148

Log:
  Document strtonum()s behavior of setting errno to 0 when no error is found.
  
  PR:             docs/143330
  Submitted by:   Efstratios Karatzas (gpf dot kira at gmail dot com)
  Discussed with: ru@
  MFC after:      7 days

Modified:
  head/lib/libc/stdlib/strtonum.3

Modified: head/lib/libc/stdlib/strtonum.3
==============================================================================
--- head/lib/libc/stdlib/strtonum.3	Thu Oct 21 18:21:19 2010	(r214147)
+++ head/lib/libc/stdlib/strtonum.3	Thu Oct 21 18:30:48 2010	(r214148)
@@ -83,6 +83,8 @@ is set, and
 .Fa errstr
 will point to an error message.
 On success,
+.Va errno
+is set to 0 and
 .Fa *errstr
 will be set to
 .Dv NULL ;
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
Comment 3 Benedict Reuschling freebsd_committer freebsd_triage 2010-10-21 19:43:09 UTC
State Changed
From-To: open->patched

Your patch was committed to HEAD. Until the MFC is done,  
this PR remains in patched state.
Comment 4 Benedict Reuschling freebsd_committer freebsd_triage 2010-10-22 09:55:58 UTC
State Changed
From-To: patched->closed

A small test program by jh@ proves that this is not the case: 
#include <err.h> 
#include <errno.h> 
#include <stdio.h> 
#include <stdlib.h> 

int 
main() 
{ 

errno = EDOOFUS; 
if (strtonum("1", 1, 10, NULL) == 0) 
err(1, "failed"); 

printf("%dn", errno); 

return (0); 
} 

The original commit was reverted in r214200. PR closed.