Skip to content

fix(taos-tools): fix sast warnings - #34719

Merged
zitsen merged 6 commits into
mainfrom
fix/6779864352
Mar 11, 2026
Merged

zitsen merged 6 commits into
mainfrom
fix/6779864352

Conversation

@YamingPei

Copy link
Copy Markdown
Contributor

Description

Fix sast warnings.

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?

Copilot AI review requested due to automatic review settings March 9, 2026 08:07

Copilot AI 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.

Pull request overview

This PR fixes SAST (Static Application Security Testing) warnings across the tools/taos-tools and tools/shell components. The changes are primarily mechanical, suppressing ignored return values and fixing type-related issues.

Changes:

  • Cast return values of functions like snprintf, sprintf, localtime_r, localtime_s, atomic_add_fetch_64, pthread_mutex_*, sem_post, closedir, benchArrayPush, argp_parse, etc. to (void) to suppress unused-return-value SAST warnings.
  • Fix type mismatches: loop variables changed from int to appropriate unsigned/sized types (uint32_t, uint8_t, size_t, etc.); comparisons involving signed/unsigned types corrected; integer conversions made explicit with casts.
  • Minor code cleanups: trailing whitespace removed, 0 replaced with NULL for pointer comparisons, (double) cast corrected to (int64_t) for timestamp, char* data = 0 corrected to char* data = NULL, null-check added for malloc in setRenameDbs and replaceNewName, variable change from int to uint32_t in fast_sqrt.

Reviewed changes

Copilot reviewed 21 out of 21 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tools/taos-tools/test/taosdumpTest.cpp Cast setConsoleEcho return values to (void)
tools/taos-tools/src/toolstime.c Cast time function return values to (void)
tools/taos-tools/src/taosdump.c Cast snprintf, atomic_add_fetch_64, closedir returns to (void); add NULL checks
tools/taos-tools/src/dumpUtil.c Cast mutex and sprintf return values to (void); fix loop variable type; fix pointer comparison
tools/taos-tools/src/benchUtilDs.c Change i from int to uint32_t in fast_sqrt; cast ds_grow/ds_add_str returns to (void)
tools/taos-tools/src/benchUtil.c Fix various type issues and cast unused returns to (void)
tools/taos-tools/src/benchTmq.c Cast snprintf returns to (void); whitespace cleanup
tools/taos-tools/src/benchSys.c Cast argp_parse/benchArrayPush returns to (void); whitespace cleanup
tools/taos-tools/src/benchQuery.c Fix signed/unsigned comparison; correct format specifier
tools/taos-tools/src/benchMain.c Cast snprintf/sem_post returns to (void); whitespace cleanup
tools/taos-tools/src/benchLog.c Cast mutex returns to (void)
tools/taos-tools/src/benchJsonOpt.c Fix type casts; remove dead scale < 0 check; cast array push returns
tools/taos-tools/src/benchInsertMix.c Fix macro comparison; cast sprintf returns to (void); whitespace
tools/taos-tools/src/benchInsert.c Fix signed/unsigned comparison; cast snprintf/sprintf returns to (void)
tools/taos-tools/src/benchDataMix.c Cast sprintf returns to (void); whitespace cleanup
tools/taos-tools/src/benchDataGeometry.c Cast benchArrayPush/benchArrayDestroy/geoObject2DToStr returns to (void)
tools/taos-tools/src/benchData.c Fix type casts; change loop variable types; cast snprintf returns to (void)
tools/taos-tools/src/benchCsv.c Fix loop variable types from uint32_t to size_t; cast time function returns
tools/taos-tools/src/benchCommandOpt.c Cast benchArrayPush/snprintf returns to (void)
tools/taos-tools/inc/benchLog.h Cast toolsGetTimeOfDay returns to (void) in log macros
tools/shell/src/shellArguments.c Cast sprintf returns to (void)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tools/taos-tools/src/benchUtilDs.c Outdated
@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 focuses on improving the code quality and addressing static analysis security testing (SAST) warnings within the taos-tools components. The changes primarily involve adding explicit (void) casts to function calls where return values are deliberately unused, enhancing type safety through explicit conversions, and implementing minor logical and formatting adjustments across various utility, benchmarking, and dumping files. These updates contribute to a cleaner codebase and reduce noise from static analysis tools.

Highlights

  • SAST Warnings Addressed: Explicit (void) casts were added to numerous function calls (e.g., sprintf, snprintf, benchArrayPush, toolsGetTimeOfDay, localtime_s, sem_post, pthread_mutex_destroy, atomic_add_fetch_64) where return values were intentionally ignored. This suppresses static analysis warnings and improves code clarity.
  • Type Safety Enhancements: Several type casts were introduced or refined, such as (float)sin, (uint32_t)pow, (int64_t)(maxInDbl * scalingFactor), and (size_t)i, to ensure correct type conversions and prevent potential implicit conversion issues.
  • Minor Code Refinements: Small logical corrections were made, including changing if (0 == pos) to if (NULL == pos) for pointer checks, adjusting loop variable types (e.g., int to uint64_t or size_t), and adding null checks for malloc calls to enhance robustness.

🧠 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/shell/src/shellArguments.c
    • Added (void) casts to sprintf calls.
  • tools/taos-tools/inc/benchLog.h
    • Added (void) casts to toolsGetTimeOfDay calls within macros.
  • tools/taos-tools/src/benchCommandOpt.c
    • Added (void) casts to benchArrayPush and snprintf calls.
    • Corrected a comparison operator in initStable.
  • tools/taos-tools/src/benchCsv.c
    • Added (void) casts to localtime_s and localtime_r calls.
    • Corrected a type cast in csvCalcCtbRange.
    • Changed uint32_t to size_t for thread_id in csvInitThreadMeta.
    • Changed uint16_t to int16_t and added (size_t) cast for benchArrayGet index in csvGenRowFields.
    • Adjusted whitespace.
  • tools/taos-tools/src/benchData.c
    • Included <inttypes.h>.
    • Added (float) casts to sin and cos results.
    • Changed int unic to uint32_t unic.
    • Added (void) casts to snprintf and benchArrayPush calls.
    • Changed int c to uint32_t c and uint32_t b in bindParamBatch loops.
    • Updated debugPrint format specifier for c from %d to %u or %zu.
  • tools/taos-tools/src/benchDataGeometry.c
    • Added (void) casts to benchArrayPush and benchArrayDestroy calls.
    • Added (void) cast to geoObject2DToStr.
  • tools/taos-tools/src/benchDataMix.c
    • Added (void) casts to sprintf and toolsFormatTimestamp calls.
    • Changed int rand_num to unsigned int rand_num.
  • tools/taos-tools/src/benchInsert.c
    • Added (void) casts to snprintf and benchArrayPush calls.
    • Corrected snprintf buffer overflow check by casting col_buffer_len - len to int.
    • Changed loop variable i from uint32_t to (int32_t)i in a loop condition.
    • Added (int64_t) cast to toolsGetTimestampMs.
  • tools/taos-tools/src/benchInsertMix.c
    • Added (int) cast to taosRandom()%100 in a macro.
    • Added (void) casts to sprintf and takeRowOutToBuf calls.
    • Fixed a comment line.
  • tools/taos-tools/src/benchJsonOpt.c
    • Fixed a comment.
    • Added (float) casts to atof results.
    • Corrected a condition if(len <= 0) to if (argsLen <= 0).
    • Changed int64_t max = RAND_MAX >> 1 to int64_t max = ((uint64_t)RAND_MAX) >> 1.
    • Corrected decimal scale validation from if (scale < 0 || scale > maxScale) to if (scale > maxScale).
    • Added (uint32_t) and (int64_t) casts for pow and multiplication results.
    • Added (void) casts to benchArrayPush calls.
    • Adjusted whitespace.
  • tools/taos-tools/src/benchLog.c
    • Added (void) casts to taosThreadMutexDestroy, taosThreadMutexLock, and taosThreadMutexUnlock calls.
  • tools/taos-tools/src/benchMain.c
    • Added (void) cast to sem_post.
    • Fixed an infoPrint format string.
    • Added (void) cast to snprintf.
    • Adjusted whitespace.
  • tools/taos-tools/src/benchQuery.c
    • Changed loop variable j from int to uint64_t in specQueryMixThread.
    • Updated errorPrint format specifier for j from %d to `%
    • Changed loop variable index from int to int64_t in specQueryThread.
  • tools/taos-tools/src/benchSys.c
    • Adjusted whitespace.
    • Added (void) cast to argp_parse.
    • Added (void) cast to benchArrayPush.
  • tools/taos-tools/src/benchTmq.c
    • Adjusted whitespace.
    • Added (void) casts to snprintf.
    • Fixed a strncmp condition.
  • tools/taos-tools/src/benchUtil.c
    • Adjusted whitespace.
    • Changed if (0 == pos) to if (NULL == pos) for pointer checks.
    • Added (void) casts to snprintf.
    • Corrected convertDatatypeToDefaultMin and convertDatatypeToDefaultMax for decimal types.
    • Changed loop variable i from int to uint8_t in decimal max/min functions.
    • Added (void) casts to snprintf in printErrCmdCodeStr and genColNames.
    • Fixed TAOS_STMT2_BINDV struct size calculation comment.
    • Fixed debugPrint format string.
  • tools/taos-tools/src/benchUtilDs.c
    • Changed int i to uint32_t i in fast_sqrt.
    • Added (uint64_t) cast to cap calculation in ds_grow.
    • Added (void) casts to ds_grow and ds_add_str.
  • tools/taos-tools/src/dumpUtil.c
    • Added (void) casts to sprintf, pthread_mutex_init, pthread_mutex_lock, pthread_mutex_unlock.
    • Changed if (colDes == 0) to if (colDes == NULL).
    • Changed loop variable i from int32_t to uint32_t in colDesToJson.
  • tools/taos-tools/src/taosdump.c
    • Added (void) casts to toolsGetTimeOfDay, atomic_add_fetch_64, setConsoleEcho, snprintf.
    • Added null checks for malloc calls.
    • Corrected char* data = 0 to char* data = NULL.
    • Changed closedir(pDir) to (void)closedir(pDir).
  • tools/taos-tools/src/toolstime.c
    • Added (void) casts to localtime_r, localtime_s, toolsGetTimeOfDay, toolsClockGetTime, usleep.
  • tools/taos-tools/test/taosdumpTest.cpp
    • Added (void) casts to setConsoleEcho.
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 static analysis warnings, primarily by casting return values of various functions to (void). While this suppresses warnings, it sometimes hides potential bugs or security vulnerabilities. I've identified several critical issues where ignoring return values could lead to crashes, deadlocks, or incorrect behavior. Specifically, error handling for mutex operations and time functions should be added. I've also pointed out unsafe sprintf calls that should be replaced with snprintf to prevent buffer overflows. On the positive side, many changes correctly fix type mismatches and remove trailing whitespace, improving code quality.

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

Comment thread tools/taos-tools/src/dumpUtil.c Outdated
Comment thread tools/taos-tools/src/benchLog.c Outdated
Comment thread tools/taos-tools/src/benchLog.c Outdated
Comment thread tools/taos-tools/src/benchLog.c Outdated
Comment thread tools/taos-tools/src/dumpUtil.c
Comment thread tools/taos-tools/src/benchMain.c Outdated
Comment thread tools/taos-tools/src/benchSys.c
Comment thread tools/taos-tools/src/benchUtil.c Outdated
Comment thread tools/taos-tools/src/dumpUtil.c Outdated
Comment thread tools/shell/src/shellArguments.c Outdated
Copilot AI review requested due to automatic review settings March 10, 2026 03:22

Copilot AI 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.

Pull request overview

Copilot reviewed 22 out of 22 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tools/taos-tools/src/dumpUtil.c
Comment thread tools/taos-tools/src/benchMain.c
@YamingPei

Copy link
Copy Markdown
Contributor Author

失败case与PR无关
image

Copilot AI review requested due to automatic review settings March 11, 2026 02:20

Copilot AI 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.

Pull request overview

Copilot reviewed 22 out of 22 changed files in this pull request and generated 6 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tools/taos-tools/src/dumpUtil.c
Comment thread tools/taos-tools/src/dumpUtil.c
Comment thread tools/taos-tools/src/benchLog.c
Comment thread tools/taos-tools/src/benchLog.c
Comment thread tools/shell/src/shellArguments.c
Comment thread tools/taos-tools/src/taosdump.c Outdated

@zitsen zitsen 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 complete. Changes look good - this PR properly addresses SAST warnings by:

  1. Casting unused return values to (void) (standard practice)
  2. Fixing type mismatches (int to uint32_t/size_t where appropriate)
  3. Converting sprintf to snprintf with buffer sizes in shellArguments.c
  4. Minor code cleanups (trailing whitespace, NULL comparisons)

No critical issues found. Safe to merge.

@zitsen
zitsen merged commit 1e8deeb into main Mar 11, 2026
12 checks passed
@zitsen
zitsen deleted the fix/6779864352 branch March 11, 2026 06:15
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.

4 participants