Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
pugs
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
code
pugs
Commits
8ea43b58
Commit
8ea43b58
authored
2 years ago
by
Stéphane Del Pino
Browse files
Options
Downloads
Patches
Plain Diff
Forbid arguments implicit conversion to N of negative integers
parent
84c11b9b
No related branches found
No related tags found
1 merge request
!145
git subrepo clone git@gitlab.com:OlMon/org-themes.git packages/org-themes
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/language/node_processor/FunctionArgumentConverter.hpp
+17
-2
17 additions, 2 deletions
src/language/node_processor/FunctionArgumentConverter.hpp
tests/test_FunctionArgumentConverter.cpp
+27
-0
27 additions, 0 deletions
tests/test_FunctionArgumentConverter.cpp
with
44 additions
and
2 deletions
src/language/node_processor/FunctionArgumentConverter.hpp
+
17
−
2
View file @
8ea43b58
...
...
@@ -65,8 +65,13 @@ class FunctionArgumentConverter final : public IFunctionArgumentConverter
if
constexpr
(
std
::
is_same_v
<
ExpectedValueType
,
ProvidedValueType
>
)
{
exec_policy
.
currentContext
()[
m_argument_id
]
=
std
::
move
(
value
);
}
else
{
exec_policy
.
currentContext
()[
m_argument_id
]
=
std
::
move
(
static_cast
<
ExpectedValueType
>
(
std
::
get
<
ProvidedValueType
>
(
value
)));
const
ProvidedValueType
&
v
=
std
::
get
<
ProvidedValueType
>
(
value
);
if
constexpr
(
std
::
is_same_v
<
uint64_t
,
ExpectedValueType
>
and
std
::
is_same_v
<
int64_t
,
ProvidedValueType
>
)
{
if
(
v
<
0
)
{
throw
std
::
domain_error
(
"trying to convert negative value ("
+
std
::
to_string
(
v
)
+
")"
);
}
}
exec_policy
.
currentContext
()[
m_argument_id
]
=
std
::
move
(
static_cast
<
ExpectedValueType
>
(
v
));
}
return
{};
}
...
...
@@ -201,6 +206,11 @@ class FunctionTupleArgumentConverter final : public IFunctionArgumentConverter
TupleType
list_value
;
list_value
.
reserve
(
v
.
size
());
for
(
size_t
i
=
0
;
i
<
v
.
size
();
++
i
)
{
if
constexpr
(
std
::
is_same_v
<
ContentType
,
uint64_t
>
and
std
::
is_same_v
<
ContentT
,
int64_t
>
)
{
if
(
v
[
i
]
<
0
)
{
throw
std
::
domain_error
(
"trying to convert negative value ("
+
std
::
to_string
(
v
[
i
])
+
")"
);
}
}
list_value
.
push_back
(
static_cast
<
ContentType
>
(
v
[
i
]));
}
exec_policy
.
currentContext
()[
m_argument_id
]
=
std
::
move
(
list_value
);
...
...
@@ -305,6 +315,11 @@ class FunctionListArgumentConverter final : public IFunctionArgumentConverter
demangle
<
ContentType
>
()
+
"'"
);
// LCOV_EXCL_STOP
}
else
if
constexpr
(
std
::
is_convertible_v
<
Vi_T
,
ContentType
>
)
{
if
constexpr
(
std
::
is_same_v
<
ContentType
,
uint64_t
>
and
std
::
is_same_v
<
Vi_T
,
int64_t
>
)
{
if
(
vi
<
0
)
{
throw
std
::
domain_error
(
"trying to convert negative value ("
+
std
::
to_string
(
vi
)
+
")"
);
}
}
list_value
.
emplace_back
(
vi
);
}
else
{
// LCOV_EXCL_START
...
...
This diff is collapsed.
Click to expand it.
tests/test_FunctionArgumentConverter.cpp
+
27
−
0
View file @
8ea43b58
...
...
@@ -208,4 +208,31 @@ TEST_CASE("FunctionArgumentConverter", "[language]")
REQUIRE
(
tuple
.
size
()
==
1
);
REQUIRE
(
tuple
[
0
].
id
()
==
f_id
);
}
SECTION
(
"error"
)
{
SECTION
(
"FunctionArgumentConverter negative value to N"
)
{
const
int64_t
negative_value
=
-
2
;
FunctionArgumentConverter
<
uint64_t
,
int64_t
>
converter
{
0
};
REQUIRE_THROWS_WITH
(
converter
.
convert
(
execution_policy
,
negative_value
),
"trying to convert negative value (-2)"
);
}
SECTION
(
"FunctionTupleOfNArgumentConverter negative value to N"
)
{
const
int64_t
i
=
1
;
const
int64_t
j
=
3
;
const
int64_t
k
=
-
6
;
FunctionTupleArgumentConverter
<
uint64_t
,
int64_t
>
converter
{
0
};
REQUIRE_THROWS_WITH
(
converter
.
convert
(
execution_policy
,
std
::
vector
<
int64_t
>
{
i
,
j
,
k
}),
"trying to convert negative value (-6)"
);
}
SECTION
(
"FunctionListArgumentConverter"
)
{
AggregateDataVariant
v
{
std
::
vector
<
DataVariant
>
{
1ul
,
-
3l
}};
FunctionListArgumentConverter
<
uint64_t
,
uint64_t
>
converter
{
2
};
REQUIRE_THROWS_WITH
(
converter
.
convert
(
execution_policy
,
v
),
"trying to convert negative value (-3)"
);
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment