Merge #10530: Fix invalid instantiation and possibly unsafe accesses of array in class base_uint<BITS>
e5c6168
Fix instantiation and array accesses in class base_uint<BITS> (Pavlos Antoniou)
Tree-SHA512: e4d39510d776c5ae8814cd5fb5c5d183cd8da937e339bff95caff68a84492fbec68bf513c5a6267446a564d39093e0c7fc703c645b511caab80f7baf7955b804
This commit is contained in:
commit
87e69c2549
2 changed files with 10 additions and 2 deletions
|
@ -15,6 +15,8 @@
|
|||
template <unsigned int BITS>
|
||||
base_uint<BITS>::base_uint(const std::string& str)
|
||||
{
|
||||
static_assert(BITS/32 > 0 && BITS%32 == 0, "Template parameter BITS must be a positive multiple of 32.");
|
||||
|
||||
SetHex(str);
|
||||
}
|
||||
|
||||
|
|
|
@ -31,12 +31,16 @@ public:
|
|||
|
||||
base_uint()
|
||||
{
|
||||
static_assert(BITS/32 > 0 && BITS%32 == 0, "Template parameter BITS must be a positive multiple of 32.");
|
||||
|
||||
for (int i = 0; i < WIDTH; i++)
|
||||
pn[i] = 0;
|
||||
}
|
||||
|
||||
base_uint(const base_uint& b)
|
||||
{
|
||||
static_assert(BITS/32 > 0 && BITS%32 == 0, "Template parameter BITS must be a positive multiple of 32.");
|
||||
|
||||
for (int i = 0; i < WIDTH; i++)
|
||||
pn[i] = b.pn[i];
|
||||
}
|
||||
|
@ -50,6 +54,8 @@ public:
|
|||
|
||||
base_uint(uint64_t b)
|
||||
{
|
||||
static_assert(BITS/32 > 0 && BITS%32 == 0, "Template parameter BITS must be a positive multiple of 32.");
|
||||
|
||||
pn[0] = (unsigned int)b;
|
||||
pn[1] = (unsigned int)(b >> 32);
|
||||
for (int i = 2; i < WIDTH; i++)
|
||||
|
@ -174,7 +180,7 @@ public:
|
|||
{
|
||||
// prefix operator
|
||||
int i = 0;
|
||||
while (++pn[i] == 0 && i < WIDTH-1)
|
||||
while (i < WIDTH && ++pn[i] == 0)
|
||||
i++;
|
||||
return *this;
|
||||
}
|
||||
|
@ -191,7 +197,7 @@ public:
|
|||
{
|
||||
// prefix operator
|
||||
int i = 0;
|
||||
while (--pn[i] == (uint32_t)-1 && i < WIDTH-1)
|
||||
while (i < WIDTH && --pn[i] == (uint32_t)-1)
|
||||
i++;
|
||||
return *this;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue