-
Notifications
You must be signed in to change notification settings - Fork 77
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
Usage of sizeof('\0') for computing the size of string terminators #276
Comments
Curious. IIRC character constants like |
You are right. And that is the "bug" that has been reported. In the code, the expression As you point out, however, this is not what happens since I am not familiar enough with the event part of the MPS code, so I don't know if it is intended to allocate "too much" for the event strings (e.g. to keep alignment), or if it is indeed a case where 3 (or 7) bytes more than intended are reserved by using |
I'm 99% certain this is a mistake on my part -- trying to express the intention of adding one to a length (to hold a NUL). In any case the fact that @fstromback isnt' sure of the interpretation that this is adding space for a NUL means the code violates rule.generic.clear. Incidentally, the Debian bug report says:
@fstromback do you know which website? |
The patch suggested in the Debian bug report looks fine to me. You're welcome to send us a pull request, @fstromback . It would help to exercise our code-review-with-external-people procedure! (Or we'll get to it anyway.) |
I'm not serious, but we could say |
Thank you for looking at it! I will prepare the patch as a pull-request shortly. Regarding the website: No, I don't know if the submitter means the webpage for Storm (which has an e-mail on the bottom of the first page, but no obvious "send patches here"), or if they mean the MPS page. I can try asking them. |
Also: after thinking about it, I like the proposal of |
It's fun but it violates rule.code.tricky exactly because you had to think about it :) |
I received a reply regarding which website was referred in the original bug report. Apparently it is the one for Storm. |
Hi!
I am maintaining the Debian package storm-lang (for the language Storm) that uses MPS. I just received a bug report related to code in the MPS. In particular, the bug report points out that the files
code/event.h
andcode/eventcom.h
both usesizeof('\0')
to compute the size of the null-terminator in a null-terminated string. When I test this on my system,sizeof('\0')
evaluates to 4, which does not look like the intended behavior. This is, however, not critical as the only effect is that "too much" memory is reserved for some buffers (if even that, due to alignment).The bug report (linked below) proposes a fix for this issue. I am happy to submit it as a pull-request if it helps you. However, since the MPS is well-engineered I figured there might be a reason for this seemingly odd code that I have missed (either a technical one, or related to style).
The bug report is here: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1058778. I have not yet tested the proposed fix, but I am happy to do so if it helps.
The text was updated successfully, but these errors were encountered: