Skip to content

fix(tools/put): ignore the retval of printf - #34730

Merged
guanshengliang merged 1 commit into
mainfrom
fix/6779898771
Mar 11, 2026
Merged

guanshengliang merged 1 commit into
mainfrom
fix/6779898771

Conversation

@stephenkgu

Copy link
Copy Markdown
Contributor

Description

Issue(s)

Checklist

Please check the items in the checklist if applicable.

  • Is the user manual updated?
  • Are the test cases passed and automated?
  • Is there no significant decrease in test coverage?

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a minor code quality improvement by modifying sprintf calls within tools/src/pub.c. The changes explicitly cast the return value of sprintf to void, signaling that the number of characters written is intentionally not used. This practice helps prevent compiler warnings and clarifies the code's intent for future maintainers. Additionally, a minor file formatting adjustment was made to ensure a consistent newline at the end of the file.

Highlights

  • sprintf return value handling: Explicitly ignored the return value of sprintf calls by casting them to (void) in tools/src/pub.c to suppress potential compiler warnings.
  • File formatting: Ensured the tools/src/pub.c file ends with a newline character.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • tools/src/pub.c
    • Ignored the return value of sprintf by casting it to (void) in error handling paths.
    • Added a missing newline character at the end of the file.
Activity
  • No specific activity (comments, reviews, etc.) has been recorded for this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request aims to fix compiler warnings about unused return values from sprintf by casting the calls to (void). While this is a valid approach to suppress the warning, I've suggested replacing the sprintf calls with strcpy for better performance and clarity, as it's more suitable for copying string literals. The change to add a newline at the end of tools/src/pub.c is a good housekeeping fix.

Note: Security Review did not run due to the size of the PR.

Comment thread tools/src/pub.c
char *p1 = strstr(dsn, "://");
if (p1 == NULL) {
sprintf(error, "%s", "dsn invalid, not found \"://\" ");
(void)sprintf(error, "%s", "dsn invalid, not found \"://\" ");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

While casting to (void) silences the compiler warning about the unused result, using sprintf with a static string is inefficient and generally unsafe due to potential buffer overflows. Although the risk is minimal here with a short string literal, it's a good practice to use safer and more direct functions.

A better approach is to use strcpy. It's more direct for this purpose, slightly more performant as it avoids format string parsing, and doesn't trigger the warn_unused_result warning in most compiler configurations.

         strcpy(error, "dsn invalid, not found \"://\" ");

Comment thread tools/src/pub.c
*pwd = p4 + 1;
} else {
sprintf(error, "%s", "dsn invalid, found \"?\" but not found \"=\" ");
(void)sprintf(error, "%s", "dsn invalid, found \"?\" but not found \"=\" ");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Similar to the other sprintf call, strcpy is more appropriate here for copying a string literal. It improves code clarity and efficiency.

         strcpy(error, "dsn invalid, found \"?\" but not found \"=\" ");

@guanshengliang
guanshengliang merged commit 4145cbb into main Mar 11, 2026
12 of 13 checks passed
@guanshengliang
guanshengliang deleted the fix/6779898771 branch March 11, 2026 02:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants