Skip to content
Closed
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/jdk.accessibility/windows/native/jabswitch/jabswitch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,9 @@ int modify(bool enable) {
printf("Couldn't create file: %s\n", path);
perror("Error");
} else {
char str[100] = "assistive_technologies=com.sun.java.accessibility.AccessBridge\n";
strcat_s(str, "screen_magnifier_present=true\n");
fprintf(origFile, str);
fprintf(origFile, "%s",
"assistive_technologies=com.sun.java.accessibility.AccessBridge\n"
"screen_magnifier_present=true\n");
Copy link
Contributor

@prrace prrace Dec 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it is what Alexander meant.
I am not sure doing the above would even resolve the complaint because there's still no format string.

I think he meant it should look like
fprintf(origfile, "%s",
"assistive_technologies=com.sun.java.accessibility.AccessBridge\n"screen_magnifier_present=true\n");
or
fprintf(origfile, "%s",
"assistive_technologies=com.sun.java.accessibility.AccessBridge\n" "screen_magnifier_present=true\n");
if you really want to use the automatic concatenation, but I had to check to be sure it would work so ..

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see your point. I'll leave it as separated again just in case the string literal is updated with anything that can be misinterpreted as a specifier.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it is what Alexander meant.

Damon understood me correctly. That's what I meant.
#28949 (comment)

I am not sure doing the above would even resolve the complaint because there's still no format string.

It should.

before:

fprintf(origFile, str); // using `str` variable as format string > parfait complains

after:

  fprintf(origFile,
      "assistive_technologies=com.sun.java.accessibility.AccessBridge\n"
      "screen_magnifier_present=true\n"); 

Here, we provide a format string(without the format specifiers), not the variable.
It's essentially identical to the code on line 301, printf("Unable to get version info.\n");, parfait didn't complain about that line.

if you really want to use the automatic concatenation, but I had to check to be sure it would work so ..

It is in the standard, so I don't see any reason not to use it:
https://en.cppreference.com/w/cpp/language/string_literal.html#Concatenation

So, in my opinion, the variable str is unnecessary here.


just in case the string literal is updated with anything that can be misinterpreted as a specifier.

I suppose it should be detected during the review process for such a change. Currently, there are no format specifiers being used.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK fair enough.

Copy link
Member

@aivanov-jdk aivanov-jdk Dec 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why can't we use fputs?

                fputs("assistive_technologies=com.sun.java.accessibility.AccessBridge\n"
                      "screen_magnifier_present=true\n",
                      origFile);

No format strings avoid any possible ambiguity and it's much faster as the string is output verbatim without any additional logic to parse a format string and to process the arguments.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the same comment applies here:

A similar pattern is used elsewhere in this file. And I don't want this fix to become a reworking of this code, because that isn't a goal here.

Thus, fprintf is fine.

Similarly, it could be worth cleaning up the code to simplify the logic by not using formatted output where it's not needed.

fclose(origFile);
}
} else {
Expand Down Expand Up @@ -314,11 +314,11 @@ void printVersion() {
pVSInfo->dwProductVersionMS & 0xFFFF,
pVSInfo->dwProductVersionLS >> 16,
pVSInfo->dwProductVersionLS & 0xFFFF );
char outputString[100];
strcpy_s(outputString, "jabswitch ");
strcat_s(outputString, versionString);
strcat_s(outputString, "\njabswitch enables or disables the Java Access Bridge.\n");
printf(outputString);
printf(
"jabswitch %s\n"
"jabswitch enables or disables the Java Access Bridge.\n",
versionString
);
Comment on lines +317 to +321
Copy link
Member

@aivanov-jdk aivanov-jdk Dec 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If versionString isn't used for anything else, we can remove the versionString variable and the call to sprintf_s and put the arguments to print the version directly into the printf call.

}

int regEnable() {
Expand Down