Skip to content

fixed some unsigned/signed compile warnings warnings & unused variables #4639

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

rommo911
Copy link

@rommo911 rommo911 commented Apr 9, 2025

fixed some unsigned/signed compile warnings warnings & unused variables

Summary by CodeRabbit

  • Refactor
    • Improved internal data consistency and indexing to ensure reliable handling of system resources.
    • Streamlined variable usage to align with expected data ranges, reducing potential warnings and enhancing overall stability.
    • Minor code optimizations have been applied to maintain a robust and responsive experience without altering user-facing functionality.

Copy link

coderabbitai bot commented Apr 9, 2025

Walkthrough

This pull request updates several variable declarations to use size_t for loop indices and selected values instead of signed integer types, ensuring type consistency with unsigned return values. Additionally, an unused variable in the connection handling logic is explicitly marked to prevent compiler warnings. These modifications span multiple files and improve type safety and code clarity in areas of indexing and variable usage.

Changes

Files Change Summary
wled00/FX_fcn.cpp, wled00/network.cpp, wled00/xml.cpp, wled00/wled.h Updated variable types from int/int8_t to size_t for loop indices and selected values to match unsigned return types and prevent signed/unsigned issues.
wled00/wled.cpp Marked the nowS variable with __attribute__((unused)) in the handleConnection method to suppress compiler warnings about unused variables.

Possibly Related PRs

  • "Unlimited" buses #4529: Modifies the finalizeInit method in the WS2812FX class with improvements in pointer safety and const correctness, aligning closely with the changes made in this pull request.

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e979c58 and 945a477.

📒 Files selected for processing (5)
  • wled00/FX_fcn.cpp (1 hunks)
  • wled00/network.cpp (1 hunks)
  • wled00/wled.cpp (1 hunks)
  • wled00/wled.h (1 hunks)
  • wled00/xml.cpp (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
wled00/FX_fcn.cpp (2)
wled00/FX.h (11)
  • i (615-615)
  • i (615-615)
  • i (663-663)
  • i (668-668)
  • i (669-669)
  • i (669-669)
  • i (670-670)
  • i (670-670)
  • i (675-675)
  • i (676-676)
  • i (937-937)
wled00/bus_manager.h (2)
  • getNumBusses (471-471)
  • getNumBusses (471-471)
🔇 Additional comments (5)
wled00/wled.h (1)

370-370: Improved type safety by using size_t for index variable

Changing selectedWiFi from int8_t to size_t is a good practice for variables used as array indices. This type is unsigned and better matches the return types of container size functions, preventing potential compiler warnings about signed/unsigned comparisons.

wled00/wled.cpp (1)

753-753: Good use of __attribute__((unused)) to suppress compiler warning

Adding the __attribute__((unused)) attribute to nowS correctly signals to the compiler that this variable is intentionally not used in the current code. This prevents compiler warnings about unused variables while maintaining the variable for potential future use or debugging purposes.

wled00/network.cpp (1)

299-299: Consistent type usage for selected variable

Changing the local variable selected from int to size_t ensures type consistency with the global variable selectedWiFi that was also changed to size_t. This prevents any potential signed/unsigned comparison issues and improves the overall type safety of the code.

wled00/FX_fcn.cpp (1)

1498-1498: Improved loop counter type to match return type of getNumBusses()

Changing the loop counter variable i from int to size_t properly aligns its type with the return type of BusManager::getNumBusses(), which returns size_t. This eliminates potential compiler warnings about signed/unsigned comparisons in the loop condition.

wled00/xml.cpp (1)

298-298: Good type change to prevent signed/unsigned comparison warnings

Changing the loop variable from int to size_t is appropriate since it's being compared with BusManager::getNumBusses(), which returns an unsigned type. This eliminates signed/unsigned comparison warnings and improves type safety.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@@ -367,7 +367,7 @@ WLED_GLOBAL wifi_options_t wifiOpt _INIT_N(({0, 1, false, AP_BEHAVIOR_BOOT_NO_CO
#define noWifiSleep wifiOpt.noWifiSleep
#define force802_3g wifiOpt.force802_3g
#else
WLED_GLOBAL int8_t selectedWiFi _INIT(0);
WLED_GLOBAL size_t selectedWiFi _INIT(0);
Copy link
Collaborator

Choose a reason for hiding this comment

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

this wastes precious ram

Copy link
Author

Choose a reason for hiding this comment

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

in that case i will put uint8_t

Copy link
Collaborator

@DedeHai DedeHai Apr 9, 2025

Choose a reason for hiding this comment

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

not a good idea, it must be signed.
unless you went through all the code where its used and are 100% sure unsigned does not lead to any undefined behavirou.

Copy link
Author

Choose a reason for hiding this comment

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

yes i have wen through all the code and ensured that its only used with positive numbers and size_t comparison.
let me know if you think i should uint8_t or just revert it

Copy link
Collaborator

Choose a reason for hiding this comment

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

Leave the networking code alone.
I have a huge modification of it waiting for upstream.

Copy link
Author

Choose a reason for hiding this comment

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

alright then

@DedeHai
Copy link
Collaborator

DedeHai commented Apr 13, 2025

in general: if you use size_t make sure there are no compile errors on all supported platforms. Did you run it on all envs?

Copy link
Collaborator

@blazoncek blazoncek left a comment

Choose a reason for hiding this comment

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

I do not agree to any change. No reason given.

@rommo911
Copy link
Author

in general: if you use size_t make sure there are no compile errors on all supported platforms. Did you run it on all envs?

as its related to wifi , i have compiled of course all esp platforms ( esp32 / S2 / C3 / ESP8266)
the reason is to avoid compiler warnings because once we have too many warnings around we could start to ignore the serious warnings...

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants