Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

StringPlcMapper does not null out full string

See original GitHub issue

One of my co-workers discovered this and it’s a bit annoying.

The way we implemented the StringPlcMapper if you write a string like “12345” it will write a value of 5 to the string.len tag and then it will write 5 bytes into the actual byte array for the string.

The issue comes about if you then write a shorter string, “abc”. The string.len will get updated to 3 and the first three bytes will be overwritten. BUT the value for the string array in the PLC will now be [a,b,c,4,5,\0,\0…] and this confuses some PLC functions and external programs.


I fixed this locally by creating a new, local mapper in my project that always writes the full max string length - padding it out with zeros. But it raises some questions:

  1. Are there any performance implications to writing extra bytes for strings?
  2. Should we do this for the different PLC types or only CLgx?
  3. Should this be optional functionality or default?

@kyle-github and @timyhac - What do you guys think?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:15 (7 by maintainers)

github_iconTop GitHub Comments

IanRobo75commented, Nov 1, 2020

I’m not sure what you are getting at. I wrote \0 because the string “ian” would be stored in a LogixPCCC PLC as \61 \69 \00 \6E. It makes sense to keep adding \00 from the next byte (5th byte here) until the end of the string (82nd byte), assuming the string is less than 82 bytes. Seems pretty safe to me, for all the PLCs I know, and extra time should be negligible.

From: timyhac Sent: Saturday, 31 October 2020 2:40 PM To: libplctag/libplctag.NET Cc: IanRobo75; Mention Subject: Re: [libplctag/libplctag.NET] StringPlcMapper does not null out full string (#101)

@kyle-github - fantastic!

@IanRobo75 - after looking at this a little bit closer, I’m 51% sure that we can simplify the LogixPcccEncode logic.

What its doing at the moment is padding a \0 character only when the string length is odd, to guarantee an even string length.

I would find it a little strange if always padding the entire structure with \0s would break other cases. What do you think about this approach?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe

kyle-githubcommented, Nov 2, 2020

@timyhac sorry, no. The comparison is always the other way when reading about how Linux mutex perform. “Looks how great Linux mutexes are, see these numbers!” And then no numbers for other platforms.

That said, there is a fairly large difference between a naive implementation of a mutex and one that tries very hard to be cheap when there is no contention. Linux tries very, very hard in that direction. That entails a lot of code which embedded systems usually leave out just due to code size considerations.

Read more comments on GitHub >

github_iconTop Results From Across the Web

String says its not null but then later throw ...
Java converts a null string to a "null" string on some conditions. Obviously the string you retrieve is not a null value, but...
Read more >
When a String is Null but Not Null
The tests went to the “not so fine here” every time. It appears the value was set to the string “null” not to...
Read more >
String.IsNullOrEmpty(String) Method (System)
Indicates whether the specified string is null or an empty string ("").
Read more >
filter non-null item properties with(out) type predicates? ...
Hi, I just simply want to collect some strings from an array of objects that can also be null. I have something like...
Read more >
Strings of Zero Length Not Equivalent To NULL - Ask TOM
According to the ANSI SQL 1992 Transitional standard, a zero-length or empty string is not the same as NULL. Ensure that applications do...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found