changed basicShift and basicFill primitives not to validate source position and destination position when count is <= 0

This commit is contained in:
hyunghwan.chung
2018-01-04 10:07:42 +00:00
parent f0df2fcd92
commit 506c6900e0
3 changed files with 64 additions and 33 deletions

View File

@ -25,7 +25,7 @@ class(#byte) IP4Address(IPAddress)
^self new fromString: str.
}
method __fromString: str
method __fromString: str offset: offset
{
| dots digits pos size c acc |
@ -41,7 +41,7 @@ class(#byte) IP4Address(IPAddress)
if (pos >= size)
{
if (dots < 3 or: [digits == 0]) { ^Error.Code.EINVAL }.
self basicAt: dots put: acc.
self basicAt: (dots + offset) put: acc.
break.
}.
@ -57,7 +57,7 @@ class(#byte) IP4Address(IPAddress)
elsif (c = $.)
{
if (dots >= 3 or: [digits == 0]) { ^Error.Code.EINVAL }.
self basicAt: dots put: acc.
self basicAt: (dots + offset) put: acc.
dots := dots + 1.
acc := 0.
digits := 0.
@ -79,24 +79,24 @@ class(#byte) IP4Address(IPAddress)
method fromString: str
{
if ((self __fromString: str) isError)
if ((self __fromString: str offset: 0) isError)
{
Exception signal: ('invalid IPv4 address ' & str).
}
}
}
class(#byte) IP6Address(IPAddress)
class(#byte) IP6Address(IP4Address)
{
method(#class) new
{
^self basicNew: 16.
}
method(#class) fromString: str
{
^self new fromString: str.
}
##method(#class) fromString: str
##{
## ^self new fromString: str.
##}
method __fromString: str
{
@ -164,7 +164,7 @@ class(#byte) IP6Address(IPAddress)
if (ch == $. and: [tgpos + 4 <= mysize])
{
IP4Address __fromString: (str copyFrom: curseg).
if ((super __fromString: (str copyFrom: curseg) offset: tgpos) isError) { ^Error.Code.EINVAL }.
tgpos := tgpos + 4.
saw_xdigit := false.
break.
@ -185,6 +185,9 @@ class(#byte) IP6Address(IPAddress)
if (colonpos >= 0)
{
## double colon position
tgpos dump.
colonpos dump.
'--------' dump.
self basicShiftFrom: colonpos to: (colonpos + (mysize - tgpos)) count: (tgpos - colonpos).
##tgpos := tgpos + (mysize - tgpos).
}
@ -378,6 +381,13 @@ s := IP4Address fromString: '192.168.123.232'.
s dump.
s basicSize dump.
##s := IP6Address fromString: 'fe80::c225:e9ff:fe47:99.2.3.4'.
##s := IP6Address fromString: '::99.12.34.54'.
s := IP6Address fromString: '::FFFF:0:0'.
s := IP6Address fromString: 'fe80::'.
s dump.
s basicSize dump.
s := IP6Address fromString: 'fe80::c225:e9ff:fe47:b1b6'.
s dump.
s basicSize dump.