Skip to content

gtk.cfg: Remove use-retval from g_file_set_contents definition - #9103

Open
Tamaranch wants to merge 1 commit into
cppcheck-opensource:mainfrom
Tamaranch:fix-g_file_set_contents-retval
Open

Tamaranch wants to merge 1 commit into
cppcheck-opensource:mainfrom
Tamaranch:fix-g_file_set_contents-retval

Conversation

@Tamaranch

Copy link
Copy Markdown
Contributor

It is acceptable to write to a file without worrying about the result in general (allowed to fail).

@dmcppcheck dmcppcheck 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.

AI review

I found no problems. The PR deletes the <use-retval/> line from g_file_set_contents in cfg/gtk.cfg, so cppcheck no longer warns when its return value is ignored. Nothing else changes, and GLib doesn't mark the function as warn-unused-result either, which fits the reasoning. One remark: test/cfg/gtk.c never calls g_file_set_contents, so no test pins the new behaviour.

Comments

# Comment By Where Status
1 No test in test/cfg/gtk.c covers g_file_set_contents AI review cfg/gtk.cfg:4065 🆕 New (false negative)

@Tamaranch, please fix, resolve or reply to the open and new comments: #1.
For #1 (false negative), it is enough to create a Trac ticket and link it here. It does not need to be fixed in this PR.

Testing

  • Build: make -j8 cppcheck in pr/ built cleanly. I didn't build testrunner because the PR changes no C++ code.
  • Library test: I ran test/cfg/gtk.c with the cppcheck options from test/cfg/runtests.sh plus --library=gtk, --error-exitcode=1 and --debug-warnings. It exited with 0 and no output.
  • Before and after: I ran this file (t.c) against both the base and the PR versions of gtk.cfg:
#include <glib.h>
void f(const char *c){
    g_file_set_contents("/tmp/x", c, -1, NULL);
    gchar *s; gsize n;
    g_file_get_contents("/tmp/x", &s, &n, NULL);
}

Command: cppcheck --library=/work/{base,pr}/cfg/gtk.cfg --enable=warning t.c

  • Base: ignoredReturnValue for both g_file_set_contents() and g_file_get_contents().
  • PR: ignoredReturnValue only for g_file_get_contents(). This is the intended change.
  • Not run: xmllint isn't installed in the container, so I couldn't check gtk.cfg against the RelaxNG schema. Deleting one empty element can't make the file invalid.

Automated review of 6464bff by Claude. The pull request was built and tested locally.

Comment thread cfg/gtk.cfg Resolved

@dmcppcheck dmcppcheck 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.

AI review

I found no new problems. The PR only deletes <use-retval/> from g_file_set_contents in cfg/gtk.cfg. The rest of the function's configuration (not-null, not-uninit, strz) still applies. The only gap is the one already raised in C2: test/cfg/gtk.c still has no call to g_file_set_contents.

Comments

# Comment By Where Status
1 No test in test/cfg/gtk.c covers g_file_set_contents AI review cfg/gtk.cfg:4065 ⚠️ Open (false negative)

@Tamaranch, please fix, resolve or reply to the open and new comments: #1.
For #1 (false negative), it is enough to create a Trac ticket and link it here. It does not need to be fixed in this PR.

Testing

  • Build: make -j8 cppcheck in pr/ built cleanly. I didn't build testrunner because the PR changes no C++ code.
  • Scratch test: I ran ./cppcheck --library=gtk --enable=warning,style --check-library t.c on this file:
#include <glib.h>
void f(const char *c){
    g_file_set_contents("/tmp/x", c, -1, NULL);
    g_file_set_contents(NULL, c, -1, NULL);
}
  • Line 3 gave no ignoredReturnValue, which is the intended change.
  • Line 4 still gave nullPointer, so the rest of the function's configuration still works.
  • Library test: I ran test/cfg/gtk.c with --library=gtk --check-library. It gave no warnings, only unmatchedSuppression notes, which come from my options rather than from the exact runtests.sh setup.
  • Not checked: I didn't build or run base/, and I didn't check gtk.cfg against the RelaxNG schema.

Automated review of 6464bff by Claude. The pull request was built and tested locally.

@dmcppcheck dmcppcheck 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.

AI review

I found no new problems. The PR only deletes <use-retval/> from g_file_set_contents in cfg/gtk.cfg. The function's other checks still work, and gtk.cfg doesn't configure any related function that should change along with it. The one gap was already raised in C1/C2: test/cfg/gtk.c still has no call to g_file_set_contents, so no test pins the new behaviour.

Comments

# Comment By Where Status
1 No test in test/cfg/gtk.c covers g_file_set_contents AI review general ⚠️ Open (false negative)
2 No test in test/cfg/gtk.c covers g_file_set_contents AI review cfg/gtk.cfg:4065 ⚠️ Open (false negative)

@Tamaranch, please fix, resolve or reply to the open and new comments: #1, #2.
For #1 and #2 (false negative), it is enough to create a Trac ticket and link it here. It does not need to be fixed in this PR.

Testing

  • Build: make -j8 cppcheck in pr/ built cleanly. I didn't build testrunner because the PR changes no C++ code.
  • XML: gtk.cfg still parses as XML (checked with Python's xml.dom.minidom). I didn't check it against the RelaxNG schema.
  • Scratch test: I ran ./cppcheck --library=gtk --enable=warning,style --check-library t.c on this file:
#include <glib.h>
void f(const char *c){
    g_file_set_contents("/tmp/x", c, -1, NULL);
    g_file_set_contents(NULL, c, -1, NULL);
}
  • Line 3 gave no ignoredReturnValue, which is the intended change.
  • Line 4 still gave nullPointer, so the function's other checks still work.
  • Test coverage: grep finds no use of g_file_set_contents anywhere in test/cfg/.

Automated review of 6464bff by Claude. The pull request was built and tested locally.

@dmcppcheck dmcppcheck 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.

AI review

I found no new problems. The PR deletes only the <use-retval/> line from g_file_set_contents in cfg/gtk.cfg. Its other settings (not-null, not-uninit, strz, not-bool) still apply. The one gap was already raised in C1/C2 and is still open: test/cfg/gtk.c has no call to g_file_set_contents, so no test pins the new behaviour.

Comments

# Comment By Where Status
1 No test in test/cfg/gtk.c covers g_file_set_contents AI review general ⚠️ Open (false negative)
2 Add a g_file_set_contents call ignoring the return value to test/cfg/gtk.c AI review cfg/gtk.cfg:4065 ⚠️ Open (false negative)

@Tamaranch, please fix, resolve or reply to the open and new comments: #1, #2.
For #1 and #2 (false negative), it is enough to create a Trac ticket and link it here. It does not need to be fixed in this PR.

Testing

  • Build: make -j8 cppcheck in pr/ built cleanly. I didn't build testrunner because the PR changes no C++ code.
  • Scratch test: I ran ./cppcheck --library=gtk --enable=warning,style --check-library -q t.c on this file:
#include <glib.h>
void f(const char *c){
    g_file_set_contents("/tmp/x", c, -1, NULL);
    g_file_set_contents(NULL, c, -1, NULL);
}
  • Line 3 gave no ignoredReturnValue, which is the intended change.
  • Line 4 still gave nullPointer, so the function's other configuration still works.
  • Library test: I ran test/cfg/gtk.c with --library=gtk --check-library --enable=style,information --inline-suppr.
    • It gave no warnings.
    • It printed only unmatchedSuppression and normalCheckLevelMaxBranches notes. These come from my options, not from the exact runtests.sh setup. Because --enable=information was on, the command exited with 1.
  • Test coverage: grep finds no use of g_file_set_contents anywhere in test/cfg/.
  • Not checked: I didn't build or run base/, and I didn't check gtk.cfg against the RelaxNG schema.

Automated review of 6464bff by Claude. The pull request was built and tested locally.

@dmcppcheck dmcppcheck 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.

AI review

I found no new problems. The PR deletes only <use-retval/> from g_file_set_contents in cfg/gtk.cfg, and the function's other settings still work. The one gap is still the one raised in C2: test/cfg/gtk.c never calls g_file_set_contents, so no test pins the new behaviour.

Comments

# Comment By Where Status
1 No test in test/cfg/gtk.c covers g_file_set_contents AI review cfg/gtk.cfg:4065 ⚠️ Open (false negative)

@Tamaranch, please fix, resolve or reply to the open and new comments: #1.
For #1 (false negative), it is enough to create a Trac ticket and link it here. It does not need to be fixed in this PR.

Testing

  • Build: make -j8 cppcheck in pr/ built cleanly. I didn't build testrunner because the PR changes no C++ code.
  • Scratch test: I ran ./cppcheck --library=gtk --enable=warning,style -q t.c on this file:
#include <glib.h>
void f(const char *c){
    g_file_set_contents("/tmp/x", c, -1, NULL);
    g_file_set_contents(NULL, c, -1, NULL);
}
  • Line 3 gave no ignoredReturnValue, which is the intended change.
  • Line 4 still gave nullPointer, so the function's other checks still work.
  • Library test: I ran test/cfg/gtk.c with --library=gtk --check-library --inline-suppr --enable=style,information. It gave no new warnings. The only output was unmatchedSuppression notes and the normalCheckLevelMaxBranches note, which come from my options rather than from the PR.
  • Test coverage: grep finds no use of g_file_set_contents anywhere in test/cfg/.
  • Not checked: I didn't build or run base/, and I didn't check gtk.cfg against the RelaxNG schema.

Automated review of 6464bff by Claude. The pull request was built and tested locally.

It is acceptable to write to a file without worrying about the result in
general (allowed to fail).
@Tamaranch
Tamaranch force-pushed the fix-g_file_set_contents-retval branch from 6464bff to b9dd69f Compare December 2, 2026 18:53

@dmcppcheck dmcppcheck 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.

AI review

I found no new problems. The PR removes <use-retval/> from g_file_set_contents in cfg/gtk.cfg. It now also adds a call in test/cfg/gtk.c that ignores the return value. That fixes the earlier review comment (C2) about the missing test: the new line fails with the old config and passes with the new one.

Comments

# Comment By Where Status
1 No test in test/cfg/gtk.c covers g_file_set_contents AI review cfg/gtk.cfg:4065 ✅ Fixed

Testing

  • Build: make -j8 cppcheck in pr/ built cleanly. I didn't build testrunner because the PR changes no C++ code.
  • PR config: I ran ./cppcheck --library=gtk --check-library --enable=style,information --inline-suppr --error-exitcode=1 -q --suppress=missingIncludeSystem --suppress=unmatchedSuppression --suppress=checkersReport --suppress=normalCheckLevelMaxBranches test/cfg/gtk.c in pr/. It printed no warnings and exited with 0.
  • Base config: I ran the same command with the same binary, but with the base cfg/gtk.cfg in its cfg folder. It failed on the new test line, which shows that the test pins the change:
    test/cfg/gtk.c:99:5: warning: Return value of function g_file_set_contents() is not used. [ignoredReturnValue]
    
  • Not run: I didn't run the full test/cfg/runtests.sh, because it needs the GTK headers.

Automated review of b9dd69f by Claude. The pull request was built and tested locally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants