mirror of
https://github.com/NixOS/nix.git
synced 2024-11-23 15:22:27 +00:00
string2Int: Barf on negative numbers for unsigned types
This commit is contained in:
parent
3baf8be1d1
commit
5b8c09c124
@ -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 New Issue
Block a user