Fix alignment bug

This commit is contained in:
moznion
2020-11-28 04:03:05 +09:00
parent fb67a5471e
commit dbe8a9f226
+4 -5
View File
@@ -31,14 +31,13 @@ impl Attributes {
attrs.push(AVP { attrs.push(AVP {
typ: bs[i], typ: bs[i],
attribute: if length > 2 { attribute: if length > 2 {
debug!("ATTR {:?}", &bs[i + 2..length]); Attribute(bs[i + 2..i + length].to_vec())
Attribute(bs[i + 2..length + 2].to_vec())
} else { } else {
Attribute(vec![]) Attribute(vec![])
}, },
}); });
i += 2 + length; i += length;
} }
Ok(Attributes(attrs)) Ok(Attributes(attrs))
@@ -86,7 +85,7 @@ impl Attributes {
return Err("attribute is too large".to_owned()); return Err("attribute is too large".to_owned());
} }
n += 1 + 1 + (attr_len as u16); n += 2 + (attr_len as u16);
} }
Ok(n) Ok(n)
@@ -101,7 +100,7 @@ impl Attributes {
return Err("attribute is too large".to_owned()); return Err("attribute is too large".to_owned());
} }
encoded.push(avp.typ); encoded.push(avp.typ);
encoded.push(attr_len as u8); encoded.push(2 + attr_len as u8);
encoded.extend(&avp.attribute.0); encoded.extend(&avp.attribute.0);
} }