-
Notifications
You must be signed in to change notification settings - Fork 1
Add MD5 checksum to debug.c as plc_program_md5 char array #19
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -162,6 +162,10 @@ def Generate_plc_debug_cvars(self): | |||||
def Generate_embedded_plc_debugger(self, st_file): | ||||||
dvars, externs, enums = self.Generate_plc_debug_cvars() | ||||||
|
||||||
MD5 = hashlib.md5(open(st_file, "rb").read()).hexdigest() | ||||||
if MD5 is None: | ||||||
raise ("Error building project: md5 object is null\n") | ||||||
Comment on lines
+166
to
+167
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The hexdigest() call always returns a 32-character string, so MD5 can never be None; additionally raise ("...") is invalid in Python 3 because a string is not an exception instance or class (will raise a TypeError if executed). Remove the unreachable conditional and, if a safeguard is still desired, raise a concrete exception type (e.g. raise RuntimeError("Failed to compute MD5")) after validating inputs earlier.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||
|
||||||
template = Environment(loader=self.__loader).get_template("debug.c.j2") | ||||||
cfile = os.path.join(paths.AbsDir(self._csvfile), "debug.c") | ||||||
debug_text = template.render( | ||||||
|
@@ -170,17 +174,14 @@ def Generate_embedded_plc_debugger(self, st_file): | |||||
"vars": dvars, | ||||||
"enums": enums, | ||||||
"types": list(set(a.split("_", 1)[0] for a in enums)), | ||||||
"md5": MD5, | ||||||
} | ||||||
) | ||||||
|
||||||
with open(cfile, "w") as f: | ||||||
f.write(debug_text) | ||||||
|
||||||
# Wrap debugger code around (* comments *) | ||||||
MD5 = hashlib.md5(open(st_file, "rb").read()).hexdigest() | ||||||
if MD5 is None: | ||||||
raise ("Error building project: md5 object is null\n") | ||||||
|
||||||
# Add MD5 value to debug.cpp file | ||||||
c_debug = 'char md5[] = "' + MD5 + '";\n' + debug_text | ||||||
|
||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The file is opened without a context manager, relying on garbage collection to close the descriptor; wrap it in with open(st_file, "rb") as f: to ensure timely resource release: with open(st_file, "rb") as f: MD5 = hashlib.md5(f.read()).hexdigest().
Copilot uses AI. Check for mistakes.