You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
> uncrustify.exe --version
Uncrustify-0.78.1_f
> echo float f1(int); | uncrustify.exe -c - -l cpp
main(1028): Parsing: 17 bytes (17 chars) from stdin as language CPP
float f1(int);
> echo float f1(int); | uncrustify.exe -c - -l cpp --tracking space:Space.html
main(1028): Parsing: 17 bytes (17 chars) from stdin as language CPP
uncrustify_file: Unable to create f1(int);
&Ý^ü☺: Invalid argument (22)
The root cause of this strange output Unable to create f1(int); and &Ý^ü☺: Invalid argument is a problem of scope in uncrustify.cpp
681: if (html_arg != nullptr)
682: {
. . .
692: char buffer[max_args_length];
693: strcpy(buffer, html_arg);
694:
695: // Tokenize and extract key and value
696: const char *tracking_art = strtok(buffer, ":");
697: const char *html_file = strtok(nullptr, ":");
698:
699: if (html_file != nullptr)
700: {
. . .
720: cpd.html_file = html_file; // <-- problem here
721: }
722: }
html_file points some where in buffer. But the scope of buffer is the block if (html_arg != nullptr){ ... }
and the global variable cpd.html_file requires a global scope.
> echo float f1(int); | uncrustify.exe -c - -l cpp --tracking space:Spaces.html
main(1028): Parsing: 17 bytes (17 chars) from stdin as language CPP
> type Space.html
<html>
<head>
...
Note:s
the memory allocated by strdup() is used until the end of the program. It is therefore not absolutely necessary to free() this memory.
the change made on line 699 is not mandatory because it is impossible to parse two --tracking, the second will be interpreted as a file name. But it may be clever to explicitly avoid memory leaks by showing that we will never call strdup() twice.
Regards.
The text was updated successfully, but these errors were encountered:
JEAYNE
changed the title
C++ scope problem with --tracking
C++ scope problem with --tracking in uncrustify.cpp
Feb 1, 2024
JEAYNE
added a commit
to JEAYNE/uncrustify.dev
that referenced
this issue
Feb 3, 2024
Demo (with WIndows)
The root cause of this strange output
Unable to create f1(int);
and&Ý^ü☺: Invalid argument
is a problem of scope in uncrustify.cpphtml_file
points some where inbuffer
. But the scope ofbuffer
is the blockif (html_arg != nullptr){ ... }
and the global variable
cpd.html_file
requires a global scope.With this fix:
the output looks good:
Note:s
Regards.
The text was updated successfully, but these errors were encountered: