nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: exercism/xgo
Pull request #614 (2017-04-06 07:13:52)

variable-length-quantity: return correct size from DecodeVarint
I noticed when I did the exercise that the `size` output that the tests expect is off by one except in the first test case.


Patch:
diff --git a/exercises/variable-length-quantity/example.go b/exercises/variable-length-quantity/example.go
index 906a28fb..685217ea 100644
--- a/exercises/variable-length-quantity/example.go
+++ b/exercises/variable-length-quantity/example.go
@@ -1,6 +1,6 @@
 package variablelengthquantity
 
-const testVersion = 1
+const testVersion = 2
 
 // EncodeVarint returns the varint encoding of x.
 func EncodeVarint(x uint32) []byte {
@@ -50,9 +50,9 @@ func DecodeVarint(buf []byte) (x uint32, n int) {
 		x = x << 7
 		x |= uint32(b) & 0x7F
 		if (b & 0x80) == 0 {
-			return x, n
+			return x, n + 1
 		}
 	}
 
-	return x, n
+	return x, 0
 }


Test patch:
diff --git a/exercises/change/change_test.go b/exercises/change/change_test.go
index aad95f55..ecb05c07 100644
--- a/exercises/change/change_test.go
+++ b/exercises/change/change_test.go
@@ -19,7 +19,7 @@ func TestChange(t *testing.T) {
 		if tc.valid {
 			if err != nil {
 				t.Fatalf("%s : Change(%v, %d): expected %v, got error %s",
-					tc.description, tc.coins, tc.target, tc.expectedChange, err)
+					tc.description, tc.coins, tc.target, tc.expectedChange, err.Error())
 			} else {
 				if !reflect.DeepEqual(actual, tc.expectedChange) {
 					t.Fatalf("%s : Change(%v, %d): expected %v, actual %v",
diff --git a/exercises/variable-length-quantity/variable_length_quantity_test.go b/exercises/variable-length-quantity/variable_length_quantity_test.go
index 23148c88..e31326ce 100644
--- a/exercises/variable-length-quantity/variable_length_quantity_test.go
+++ b/exercises/variable-length-quantity/variable_length_quantity_test.go
@@ -5,7 +5,7 @@ import (
 	"testing"
 )
 
-const targetTestVersion = 1
+const targetTestVersion = 2
 
 var testCases = []struct {
 	input  []byte
@@ -13,16 +13,16 @@ var testCases = []struct {
 	size   int
 }{
 	0:  {[]byte{0x7F}, 127, 1},
-	1:  {[]byte{0x81, 0x00}, 128, 1},
-	2:  {[]byte{0xC0, 0x00}, 8192, 1},
-	3:  {[]byte{0xFF, 0x7F}, 16383, 1},
-	4:  {[]byte{0x81, 0x80, 0x00}, 16384, 2},
-	5:  {[]byte{0xFF, 0xFF, 0x7F}, 2097151, 2},
-	6:  {[]byte{0x81, 0x80, 0x80, 0x00}, 2097152, 3},
-	7:  {[]byte{0xC0, 0x80, 0x80, 0x00}, 134217728, 3},
-	8:  {[]byte{0xFF, 0xFF, 0xFF, 0x7F}, 268435455, 3},
-	9:  {[]byte{0x82, 0x00}, 256, 1},
-	10: {[]byte{0x81, 0x10}, 144, 1},
+	1:  {[]byte{0x81, 0x00}, 128, 2},
+	2:  {[]byte{0xC0, 0x00}, 8192, 2},
+	3:  {[]byte{0xFF, 0x7F}, 16383, 2},
+	4:  {[]byte{0x81, 0x80, 0x00}, 16384, 3},
+	5:  {[]byte{0xFF, 0xFF, 0x7F}, 2097151, 3},
+	6:  {[]byte{0x81, 0x80, 0x80, 0x00}, 2097152, 4},
+	7:  {[]byte{0xC0, 0x80, 0x80, 0x00}, 134217728, 4},
+	8:  {[]byte{0xFF, 0xFF, 0xFF, 0x7F}, 268435455, 4},
+	9:  {[]byte{0x82, 0x00}, 256, 2},
+	10: {[]byte{0x81, 0x10}, 144, 2},
 }
 
 func TestTestVersion(t *testing.T) {
Repository: gopcua/opcua
Pull request #174 (2019-04-23 20:48:40)

Rename NewNodeID to ParseNodeID
See #173 for discussion.


Patch:
diff --git a/examples/read/read.go b/examples/read/read.go
index f2f0b16..f62428c 100644
--- a/examples/read/read.go
+++ b/examples/read/read.go
@@ -28,7 +28,7 @@ func main() {
 	}
 	defer c.Close()
 
-	id, err := ua.NewNodeID(*nodeID)
+	id, err := ua.ParseNodeID(*nodeID)
 	if err != nil {
 		log.Fatalf("invalid node id: %v", err)
 	}
diff --git a/examples/write/write.go b/examples/write/write.go
index cdfcc36..e38597b 100644
--- a/examples/write/write.go
+++ b/examples/write/write.go
@@ -29,7 +29,7 @@ func main() {
 	}
 	defer c.Close()
 
-	id, err := ua.NewNodeID(*nodeID)
+	id, err := ua.ParseNodeID(*nodeID)
 	if err != nil {
 		log.Fatalf("invalid node id: %v", err)
 	}
diff --git a/ua/node_id.go b/ua/node_id.go
index 30ea0f8..8533e8c 100644
--- a/ua/node_id.go
+++ b/ua/node_id.go
@@ -77,7 +77,7 @@ func NewByteStringNodeID(ns uint16, id []byte) *NodeID {
 	}
 }
 
-// NewNodeID returns a node id from a string definition of the format
+// ParseNodeID returns a node id from a string definition of the format
 // 'ns=<namespace>;{s,i,b,g}=<identifier>'.
 //
 // For string node ids the 's=' prefix can be omitted.
@@ -87,7 +87,7 @@ func NewByteStringNodeID(ns uint16, id []byte) *NodeID {
 //
 // Namespace URLs 'nsu=' are not supported since they require a lookup.
 //
-func NewNodeID(s string) (*NodeID, error) {
+func ParseNodeID(s string) (*NodeID, error) {
 	if s == "" {
 		return NewTwoByteNodeID(0), nil
 	}
@@ -304,7 +304,7 @@ func (n *NodeID) SetStringID(v string) error {
 }
 
 // String returns the string representation of the NodeID
-// in the format described by NewNodeID.
+// in the format described by ParseNodeID.
 func (n *NodeID) String() string {
 	switch n.Type() {
 	case NodeIDTypeTwoByte:


Test patch:
diff --git a/ua/node_id_test.go b/ua/node_id_test.go
index 513c077..9bd9ee7 100644
--- a/ua/node_id_test.go
+++ b/ua/node_id_test.go
@@ -112,7 +112,7 @@ func BenchmarkReflectDecode(b *testing.B) {
 	}
 }
 
-func TestNewNodeID(t *testing.T) {
+func TestParseNodeID(t *testing.T) {
 	cases := []struct {
 		s   string
 		n   *NodeID
@@ -143,7 +143,7 @@ func TestNewNodeID(t *testing.T) {
 
 	for _, c := range cases {
 		t.Run(c.s, func(t *testing.T) {
-			n, err := NewNodeID(c.s)
+			n, err := ParseNodeID(c.s)
 			if got, want := err, c.err; !reflect.DeepEqual(got, want) {
 				t.Fatalf("got error %v want %v", got, want)
 			}
Repository: gopcua/opcua
Pull request #249 (2019-07-24 11:04:46)

add variant array limit
fix for #248 

kung-foo: lol. if you force push (to first remove a merge commit) and it results in an "empty" PR, it seems like github automatically "merges" and closes it. :man_shrugging: will re-create.
kung-foo: rebased and test code moved into own func

Regarding the error code, as a user, I want to be able to quickly figure out why I got the error. I could return something like `io.ErrShortBuffer`, but that isn't exactly right because it's not that the buffer is too small, it's that we (arbitrarily) added a safety limit. IMO, errors should clearly explain what is going on, and what the user needs to do to fix it. 
magiconair: So far we've been trying to stick to the available `StatusCode`s for consistency and I'm wondering whether we can use one of them. There is `StatusBadEncodingLimitsExceeded` which seems close but I also get your point. Question is how often that's going to happen to justify an exception for not using a status code. 

Could you have a quick look how FreeOPCUA and open62541 are handling this?
magiconair: Maybe also squash the commits since now your change to `CodecTest` and the reverse is in. Unless I'm missing something.
kung-foo: ahh, I see your point re the `StatusCode`. I wasn't familiar with that code. I'll change and squash.

Patch:
diff --git a/ua/variant.go b/ua/variant.go
index e0be496..22ce0cb 100644
--- a/ua/variant.go
+++ b/ua/variant.go
@@ -11,6 +11,11 @@ import (
 	"time"
 )
 
+var (
+	// MaxVariantArrayLength sets a limit on the number of elements in array
+	MaxVariantArrayLength = 0xffff
+)
+
 const (
 	// VariantArrayDimensions flags whether the array has more than one dimension
 	VariantArrayDimensions = 0x40
@@ -124,6 +129,12 @@ func (m *Variant) Decode(b []byte) (int, error) {
 
 	// read flattened array elements
 	n := int(m.arrayLength)
+
+	if n > MaxVariantArrayLength {
+		return buf.Pos(), StatusBadEncodingLimitsExceeded
+	}
+
+	// note: if n is negative (since we read a _signed_ int32) MakeSlice will panic
 	vals := reflect.MakeSlice(reflect.SliceOf(typ), n, n)
 	for i := 0; i < n; i++ {
 		vals.Index(i).Set(reflect.ValueOf(m.decodeValue(buf)))


Test patch:
diff --git a/ua/variant_test.go b/ua/variant_test.go
index 528c9a9..96e09cf 100644
--- a/ua/variant_test.go
+++ b/ua/variant_test.go
@@ -468,6 +468,23 @@ func TestVariant(t *testing.T) {
 	RunCodecTest(t, cases)
 }
 
+func TestBigArray(t *testing.T) {
+	b := []byte{
+		// variant encoding mask
+		0x87,
+		// array length
+		0xff, 0xff, 0x01, 0x00,
+		// array values
+		0x00, 0x00, 0x00, 0x00,
+	}
+
+	_, err := Decode(b, MustVariant([]uint32{0}))
+
+	if err != StatusBadEncodingLimitsExceeded {
+		t.Fatalf("got error %v want %v", err, StatusBadEncodingLimitsExceeded)
+	}
+}
+
 func TestSet(t *testing.T) {
 	tests := []struct {
 		v   interface{}
Repository: gopcua/opcua
Pull request #263 (2019-09-03 06:15:13)

Rename XmlElement to XMLElement
I've done this for all other types but missed this one.


Patch:
diff --git a/ua/datatypes.go b/ua/datatypes.go
index f5b7c2d..0268f53 100644
--- a/ua/datatypes.go
+++ b/ua/datatypes.go
@@ -234,4 +234,4 @@ func (l *LocalizedText) UpdateMask() {
 	}
 }
 
-type XmlElement string
+type XMLElement string
diff --git a/ua/extension_object.go b/ua/extension_object.go
index e409fc6..5219af1 100644
--- a/ua/extension_object.go
+++ b/ua/extension_object.go
@@ -82,7 +82,7 @@ func (e *ExtensionObject) Decode(b []byte) (int, error) {
 	}
 
 	if e.EncodingMask == ExtensionObjectXML {
-		e.Value = new(XmlElement)
+		e.Value = new(XMLElement)
 		body.ReadStruct(e.Value)
 		return buf.Pos(), body.Error()
 	}
@@ -121,7 +121,7 @@ func (e *ExtensionObject) Encode() ([]byte, error) {
 func (e *ExtensionObject) UpdateMask() {
 	if e.Value == nil {
 		e.EncodingMask = ExtensionObjectEmpty
-	} else if _, ok := e.Value.(*XmlElement); ok {
+	} else if _, ok := e.Value.(*XMLElement); ok {
 		e.EncodingMask = ExtensionObjectXML
 	} else {
 		e.EncodingMask = ExtensionObjectBinary
diff --git a/ua/variant.go b/ua/variant.go
index 22ce0cb..d9f5636 100644
--- a/ua/variant.go
+++ b/ua/variant.go
@@ -253,7 +253,7 @@ func (m *Variant) decodeValue(buf *Buffer) interface{} {
 	case TypeIDByteString:
 		return buf.ReadBytes()
 	case TypeIDXMLElement:
-		return XmlElement(buf.ReadString())
+		return XMLElement(buf.ReadString())
 	case TypeIDNodeID:
 		v := new(NodeID)
 		buf.ReadStruct(v)
@@ -361,7 +361,7 @@ func (m *Variant) encodeValue(buf *Buffer, v interface{}) {
 		buf.WriteStruct(x)
 	case []byte:
 		buf.WriteByteString(x)
-	case XmlElement:
+	case XMLElement:
 		buf.WriteString(string(x))
 	case *NodeID:
 		buf.WriteStruct(x)
@@ -548,7 +548,7 @@ var variantTypeIDToType = map[TypeID]reflect.Type{
 	TypeIDDateTime:        reflect.TypeOf(time.Time{}),
 	TypeIDGUID:            reflect.TypeOf(new(GUID)),
 	TypeIDByteString:      reflect.TypeOf([]byte{}),
-	TypeIDXMLElement:      reflect.TypeOf(XmlElement("")),
+	TypeIDXMLElement:      reflect.TypeOf(XMLElement("")),
 	TypeIDNodeID:          reflect.TypeOf(new(NodeID)),
 	TypeIDExpandedNodeID:  reflect.TypeOf(new(ExpandedNodeID)),
 	TypeIDStatusCode:      reflect.TypeOf(StatusCode(0)),


Test patch:
diff --git a/ua/variant_test.go b/ua/variant_test.go
index 96e09cf..fd2de49 100644
--- a/ua/variant_test.go
+++ b/ua/variant_test.go
@@ -169,8 +169,8 @@ func TestVariant(t *testing.T) {
 			},
 		},
 		{
-			Name:   "XmlElement",
-			Struct: MustVariant(XmlElement("abc")),
+			Name:   "XMLElement",
+			Struct: MustVariant(XMLElement("abc")),
 			Bytes: []byte{
 				// variant encoding mask
 				0x10,