Avoid increasing str pointer with wrapped value when length is 0.
@@ -159,6 +159,7 @@ snmp_ber_encode_string_len(snmp_packet_t *snmp_packet, const char *str, uint32_t
{
uint32_t i;
+ if(length > 0) {
str += length - 1;
for(i = 0; i < length; ++i) {
if(snmp_packet->used == snmp_packet->max) {
@@ -168,6 +169,7 @@ snmp_ber_encode_string_len(snmp_packet_t *snmp_packet, const char *str, uint32_t
*snmp_packet->out-- = (uint8_t)*str--;
snmp_packet->used++;
}
+ }
if(!snmp_ber_encode_length(snmp_packet, length)) {
return 0;
