string2Int: Barf on negative numbers for unsigned types
This commit is contained in:
		
							parent
							
								
									3baf8be1d1
								
							
						
					
					
						commit
						5b8c09c124
					
				
					 1 changed files with 3 additions and 1 deletions
				
			
		|  | @ -8,7 +8,7 @@ | ||||||
| #include <unistd.h> | #include <unistd.h> | ||||||
| #include <signal.h> | #include <signal.h> | ||||||
| #include <functional> | #include <functional> | ||||||
| 
 | #include <limits> | ||||||
| #include <cstdio> | #include <cstdio> | ||||||
| 
 | 
 | ||||||
| #ifndef HAVE_STRUCT_DIRENT_D_TYPE | #ifndef HAVE_STRUCT_DIRENT_D_TYPE | ||||||
|  | @ -359,6 +359,8 @@ bool statusOk(int status); | ||||||
| /* Parse a string into an integer. */ | /* Parse a string into an integer. */ | ||||||
| template<class N> bool string2Int(const string & s, N & n) | template<class N> bool string2Int(const string & s, N & n) | ||||||
| { | { | ||||||
|  |     if (string(s, 0, 1) == "-" && !std::numeric_limits<N>::is_signed) | ||||||
|  |         return false; | ||||||
|     std::istringstream str(s); |     std::istringstream str(s); | ||||||
|     str >> n; |     str >> n; | ||||||
|     return str && str.get() == EOF; |     return str && str.get() == EOF; | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue