Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix casting to byte for integer greater than 127 (byte is signed numb… #339

Merged
merged 2 commits into from
Apr 7, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2032,8 +2032,8 @@ public static void serializeS7Char(WriteBuffer io, PlcValue value, String encodi
* the String as char arrays from your application.
*/
public static void serializeS7String(WriteBuffer io, PlcValue value, int stringLength, String encoding) {
byte k = (byte) ((stringLength > 250) ? 250 : stringLength);
byte m = (byte) value.getString().length();
int k = 0xFF & ((stringLength > 250) ? 250 : stringLength);
int m = 0xFF & value.getString().length();
m = (m > k) ? k : m;
byte[] chars = new byte[m];
for (int i = 0; i < m; ++i) {
Expand All @@ -2042,8 +2042,8 @@ public static void serializeS7String(WriteBuffer io, PlcValue value, int stringL
}

try {
io.writeByte(k);
io.writeByte(m);
io.writeByte((byte)(k & 0xFF));
io.writeByte((byte)(m & 0xFF));
io.writeByteArray(chars);
} catch (SerializationException ex) {
Logger.getLogger(StaticHelper.class.getName()).log(Level.SEVERE, null, ex);
Expand Down