mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-29 17:16:15 +02:00
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 <signal.h>
|
||||
#include <functional>
|
||||
|
||||
#include <limits>
|
||||
#include <cstdio>
|
||||
|
||||
#ifndef HAVE_STRUCT_DIRENT_D_TYPE
|
||||
|
@ -359,6 +359,8 @@ bool statusOk(int status);
|
|||
/* Parse a string into an integer. */
|
||||
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);
|
||||
str >> n;
|
||||
return str && str.get() == EOF;
|
||||
|
|
Loading…
Reference in a new issue