You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The function raising the errors is sortedErrors.Less:
func (s sortedErrors) Less(i, j int) bool {
fi := strings.SplitN(s[i].s, ":", 4)
fj := strings.SplitN(s[j].s, ":", 4)
if fi[0] < fj[0] {
return true
}
if fi[0] > fj[0] {
return false
}
// compare compares field x to see which is less.
// numbers are compared as numbers.
compare := func(x int) int {
switch {
case len(fi) == x && len(fj) > x:
return -1
case len(fj) == x && len(fi) > x:
return 1
case len(fj) < x || len(fi) < x:
return 0
}
return nless(fi[x], fj[x])
}
for x := 1; x < 4; x++ {
switch compare(1) {
case -1:
return true
case 1:
return false
}
}
return false
}
Two observations here:
I am not sure why the loop between 1 and 4, when the compare function is only being called with 1.
A new case should be added in the compare function to test for the out of range. Alternative, the case len(fj) < x || len(fi) < x should probably be modified to test that x - 1is not larger than the length of both arrays. Note that x is not a length, but a position in the array (starting with 0).
Thanks.
The text was updated successfully, but these errors were encountered:
Thanks, would agree the call compare(1) is in error.
This sort function is designed to sort an incoming string (from some error.Error()) by filename, then line number, column number and finally the error message, so the loop bounds look accurate, because we compared the 0th element (filename) in the first two branches of the function before checking further fields in the case of the first being equal.
However, we can produce error strings which don't have 4 fields; I suspect this type of message was the case here. As strings.SplitN returns a slice with maximum length of its final argument, agree with the bounds checking observation to avoid the panic.
Hello,
I am using goyang to process MIB-YANG modules obtained after converting SMIv2 files with SMIDUMP.
This issue is about special errors that trigger "index out of range" while processing a module.
To reproduce:
goyang CISCO-IMAGE-TC.yang
Output should be:
The function raising the errors is sortedErrors.Less:
Two observations here:
Thanks.
The text was updated successfully, but these errors were encountered: