Skip to content

Commit

Permalink
- fixed bug in BerInteger_setUint16
Browse files Browse the repository at this point in the history
  • Loading branch information
mzillgith committed Sep 21, 2019
1 parent e4c3875 commit 6e90479
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
3 changes: 1 addition & 2 deletions src/mms/asn1/ber_encoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,6 @@ BerEncoder_revertByteOrder(uint8_t* octets, const int size)
int
BerEncoder_compressInteger(uint8_t* integer, int originalSize)
{

uint8_t* integerEnd = integer + originalSize - 1;
uint8_t* bytePosition;

Expand All @@ -205,7 +204,7 @@ BerEncoder_compressInteger(uint8_t* integer, int originalSize)
continue;
}
else if (bytePosition[0] == 0xff) {
if (bytePosition[1] & 0x80)
if ((bytePosition[1] & 0x80) == 0x80)
continue;
}

Expand Down
20 changes: 18 additions & 2 deletions src/mms/asn1/ber_integer.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* ber_integer.c
*
* Copyright 2013 Michael Zillgith
* Copyright 2013-2019 Michael Zillgith
*
* This file is part of libIEC61850.
*
Expand Down Expand Up @@ -106,7 +106,23 @@ BerInteger_setUint16(Asn1PrimitiveValue* self, uint16_t value)
uint16_t valueCopy = value;
uint8_t* valueBuffer = (uint8_t*) &valueCopy;

return setIntegerValue(self, valueBuffer, sizeof(value));
uint8_t byteBuffer[3];

int i;

#if (ORDER_LITTLE_ENDIAN == 1)
byteBuffer[2] = 0;

for (i = 0; i < 2; i++)
byteBuffer[i] = valueBuffer[i];
#else
byteBuffer[0] = 0;

for (i = 0; i < 2; i++)
byteBuffer[i + 1] = valueBuffer[i];
#endif /* (ORDER_LITTLE_ENDIAN == 1) */

return setIntegerValue(self, byteBuffer, sizeof(byteBuffer));
}

int
Expand Down

0 comments on commit 6e90479

Please sign in to comment.