mirror of
https://github.com/zeek/zeek.git
synced 2025-10-03 23:28:20 +00:00
factoring out logic to check for overflows during coercions
This commit is contained in:
parent
9757d37332
commit
a67897135e
8 changed files with 89 additions and 37 deletions
33
src/Overflow.h
Normal file
33
src/Overflow.h
Normal file
|
@ -0,0 +1,33 @@
|
|||
// See the file "COPYING" in the main distribution directory for copyright.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "zeek/Type.h"
|
||||
|
||||
namespace zeek::detail {
|
||||
|
||||
inline bool double_to_count_would_overflow(double v)
|
||||
{
|
||||
return v < 0.0 || v > static_cast<double>(UINT64_MAX);
|
||||
}
|
||||
|
||||
inline bool int_to_count_would_overflow(bro_int_t v)
|
||||
{
|
||||
return v < 0.0;
|
||||
}
|
||||
|
||||
inline bool double_to_int_would_overflow(double v)
|
||||
{
|
||||
return v < static_cast<double>(INT64_MIN) ||
|
||||
v > static_cast<double>(INT64_MAX);
|
||||
}
|
||||
|
||||
inline bool count_to_int_would_overflow(bro_uint_t v)
|
||||
{
|
||||
return v > INT64_MAX;
|
||||
}
|
||||
|
||||
extern bool would_overflow(const zeek::Type* from_type,
|
||||
const zeek::Type* to_type, const Val* val);
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue