sencode: ensure bijective int serialization
This commit is contained in:
parent
765c553e97
commit
7f8e02a8aa
|
@ -27,6 +27,22 @@ static void parse_int (const std::string&str, int&pos, int len,
|
||||||
res = 0;
|
res = 0;
|
||||||
++pos; //skip 'i'
|
++pos; //skip 'i'
|
||||||
if (pos >= len) goto fail;
|
if (pos >= len) goto fail;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Strip special cases: Don't support the "empty zero" in form of 'ie'.
|
||||||
|
* Also, only purpose for having a leading zero in integers is to have
|
||||||
|
* actual 'i0e' zero. Other cases are disallowed because serialization
|
||||||
|
* would not be bijective otherwise.
|
||||||
|
*/
|
||||||
|
if (str[pos] == 'e') goto fail;
|
||||||
|
if (str[pos] == '0') {
|
||||||
|
++pos;
|
||||||
|
if (pos < len && str[pos] == 'e') {
|
||||||
|
res = 0;
|
||||||
|
return;
|
||||||
|
} else goto fail;
|
||||||
|
}
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
if (pos >= len) goto fail; //not terminated
|
if (pos >= len) goto fail; //not terminated
|
||||||
else if (str[pos] == 'e') break; //done good
|
else if (str[pos] == 'e') break; //done good
|
||||||
|
|
|
@ -50,7 +50,7 @@ public:
|
||||||
class sencode_int: public sencode
|
class sencode_int: public sencode
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
unsigned int i;
|
uint i;
|
||||||
sencode_int (unsigned int I) {
|
sencode_int (unsigned int I) {
|
||||||
i = I;
|
i = I;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue