Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
8af75c78
Commit
8af75c78
authored
Jul 17, 2018
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
config/{Global,Block}: throw exception on parser error
parent
696add25
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
17 deletions
+17
-17
Block.cxx
src/config/Block.cxx
+7
-8
Global.cxx
src/config/Global.cxx
+10
-9
No files found.
src/config/Block.cxx
View file @
8af75c78
...
...
@@ -21,7 +21,6 @@
#include "Block.hxx"
#include "Parser.hxx"
#include "Path.hxx"
#include "system/FatalError.hxx"
#include "fs/AllocatedPath.hxx"
#include "util/RuntimeError.hxx"
...
...
@@ -35,7 +34,7 @@ BlockParam::GetIntValue() const
char
*
endptr
;
long
value2
=
strtol
(
s
,
&
endptr
,
0
);
if
(
endptr
==
s
||
*
endptr
!=
0
)
FormatFatal
Error
(
"Not a valid number in line %i"
,
line
);
throw
FormatRuntime
Error
(
"Not a valid number in line %i"
,
line
);
return
value2
;
}
...
...
@@ -47,7 +46,7 @@ BlockParam::GetUnsignedValue() const
char
*
endptr
;
unsigned
long
value2
=
strtoul
(
s
,
&
endptr
,
0
);
if
(
endptr
==
s
||
*
endptr
!=
0
)
FormatFatal
Error
(
"Not a valid number in line %i"
,
line
);
throw
FormatRuntime
Error
(
"Not a valid number in line %i"
,
line
);
return
(
unsigned
)
value2
;
}
...
...
@@ -59,10 +58,10 @@ BlockParam::GetPositiveValue() const
char
*
endptr
;
unsigned
long
value2
=
strtoul
(
s
,
&
endptr
,
0
);
if
(
endptr
==
s
||
*
endptr
!=
0
)
FormatFatal
Error
(
"Not a valid number in line %i"
,
line
);
throw
FormatRuntime
Error
(
"Not a valid number in line %i"
,
line
);
if
(
value2
<=
0
)
FormatFatal
Error
(
"Number in line %i must be positive"
,
line
);
throw
FormatRuntime
Error
(
"Number in line %i must be positive"
,
line
);
return
(
unsigned
)
value2
;
}
...
...
@@ -72,9 +71,9 @@ BlockParam::GetBoolValue() const
{
bool
value2
;
if
(
!
get_bool
(
value
.
c_str
(),
&
value2
))
FormatFatal
Error
(
"%s is not a boolean value (yes, true, 1) or "
"(no, false, 0) on line %i
\n
"
,
name
.
c_str
(),
line
);
throw
FormatRuntime
Error
(
"%s is not a boolean value (yes, true, 1) or "
"(no, false, 0) on line %i
\n
"
,
name
.
c_str
(),
line
);
return
value2
;
}
...
...
src/config/Global.cxx
View file @
8af75c78
...
...
@@ -28,7 +28,7 @@
#include "Domain.hxx"
#include "fs/Path.hxx"
#include "fs/AllocatedPath.hxx"
#include "
system/Fatal
Error.hxx"
#include "
util/Runtime
Error.hxx"
#include "Log.hxx"
#include <stdlib.h>
...
...
@@ -126,8 +126,8 @@ config_get_unsigned(ConfigOption option, unsigned default_value)
const
char
*
const
s
=
param
->
value
.
c_str
();
value
=
strtol
(
s
,
&
endptr
,
0
);
if
(
endptr
==
s
||
*
endptr
!=
0
||
value
<
0
)
FormatFatal
Error
(
"Not a valid non-negative number in line %i"
,
param
->
line
);
throw
FormatRuntime
Error
(
"Not a valid non-negative number in line %i"
,
param
->
line
);
return
(
unsigned
)
value
;
}
...
...
@@ -145,11 +145,12 @@ config_get_positive(ConfigOption option, unsigned default_value)
const
char
*
const
s
=
param
->
value
.
c_str
();
value
=
strtol
(
s
,
&
endptr
,
0
);
if
(
endptr
==
s
||
*
endptr
!=
0
)
FormatFatalError
(
"Not a valid number in line %i"
,
param
->
line
);
throw
FormatRuntimeError
(
"Not a valid number in line %i"
,
param
->
line
);
if
(
value
<=
0
)
FormatFatal
Error
(
"Not a positive number in line %i"
,
param
->
line
);
throw
FormatRuntime
Error
(
"Not a positive number in line %i"
,
param
->
line
);
return
(
unsigned
)
value
;
}
...
...
@@ -165,9 +166,9 @@ config_get_bool(ConfigOption option, bool default_value)
success
=
get_bool
(
param
->
value
.
c_str
(),
&
value
);
if
(
!
success
)
FormatFatal
Error
(
"Expected boolean value (yes, true, 1) or "
"(no, false, 0) on line %i
\n
"
,
param
->
line
);
throw
FormatRuntime
Error
(
"Expected boolean value (yes, true, 1) or "
"(no, false, 0) on line %i
\n
"
,
param
->
line
);
return
value
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment