fix(contrib/mqtt): ignore unused retval#34735
Conversation
Summary of ChangesHello, 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 focuses on improving code hygiene within the MQTT contributor library by explicitly marking function return values that are intentionally ignored. This change suppresses compiler warnings and clarifies the code's intent without altering its functional behavior, ensuring a cleaner build process. Highlights
🧠 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
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
Code Review
The pull request primarily introduces UNUSED() macros around various function calls in ttqMisc.c, ttqNet.c, ttqNet2.c, ttqPacket.c, ttqSendPublish.c, and ttqUtil.c to silence compiler warnings about unused return values. Review comments highlight that ignoring these return values for functions like ttqMuxAddOut(), ttqMuxRemoveOut(), packet__write_varint(), getpwuid_r(), getgrgid_r(), and net__init() could lead to issues such as stalled packets, incorrect event monitoring, malformed packets, or masked system/initialization errors. The reviewer suggests checking and handling these return values to improve robustness and prevent potential bugs.
| struct passwd pw, *result; | ||
|
|
||
| getpwuid_r(getuid(), &pw, buf, sizeof(buf), &result); | ||
| UNUSED(getpwuid_r(getuid(), &pw, buf, sizeof(buf), &result)); |
There was a problem hiding this comment.
While UNUSED silences the compiler warning, it's better to handle the return value of getpwuid_r. It returns an error code on failure (e.g., if the buffer is too small), which is different from not finding a user. Ignoring this error could hide underlying system issues. Consider checking the return value and logging an error if it's non-zero.
| struct group grp, *result; | ||
|
|
||
| getgrgid_r(getgid(), &grp, buf, sizeof(buf), &result); | ||
| UNUSED(getgrgid_r(getgid(), &grp, buf, sizeof(buf), &result)); |
| int rc = net__init_ssl_ctx(ttq); | ||
| if (rc) { | ||
| net__socket_close(ttq); | ||
| UNUSED(net__socket_close(ttq)); |
There was a problem hiding this comment.
| void ttqNetBrokerInit(void) { | ||
| spare_sock = socket(AF_INET, SOCK_STREAM, 0); | ||
| net__init(); | ||
| UNUSED(net__init()); |
There was a problem hiding this comment.
Description
Issue(s)
https://project.feishu.cn/taosdata_td/defect/detail/6779787380
Checklist
Please check the items in the checklist if applicable.