New issue

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

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

Already on GitHub? Sign in to your account

resolve LWIP compiler warning #6780

Merged
merged 2 commits into from May 3, 2018

Conversation

Projects
None yet
4 participants
@bmcdonnell-ionx
Contributor

bmcdonnell-ionx commented Apr 30, 2018

Description

Cast a variable to resolve a compiler warning.

Compile [ 12.3%]: lpc17_emac.c
[Warning] lpc17_emac.c@614,20: comparison between signed and unsigned integer expressions [-Wsign-compare]

There is probably a more straight-forward / maintainable way to do it, so feel free to improve on this PR.

Pull request type

[X] Fix
[ ] Refactor
[ ] New target
[ ] Feature
[ ] Breaking change

@0xc0170 0xc0170 requested a review from kjbracey-arm May 2, 2018

for (idx = 0; idx < dn; idx++) {
/* It is safe to cast dn to uint32 here since it is either derived from the
* uint16 returned by pbuf_clen() above, or it is set to 1. */
for (idx = 0; idx < (u32_t) dn; idx++) {

This comment has been minimized.

@kjbracey-arm

kjbracey-arm May 2, 2018

Contributor

If we can avoid a cast, would be sweet. In this case the problem is that this unsigned idx is intended for use elsewhere as the unsigned descriptor index, but this loop is actually comparing with the descriptor count.

No reason to use the same variable. Just have a local s_32_t count as the loop variable here.

@bmcdonnell-ionx bmcdonnell-ionx force-pushed the bmcdonnell-ionx:fix-lwip-compiler-warning branch from c696a14 to ba29bd9 May 2, 2018

@bmcdonnell-ionx

This comment has been minimized.

Contributor

bmcdonnell-ionx commented May 2, 2018

@kjbracey-arm

No reason to use the same variable. Just have a local s_32_t count as the loop variable here.

Done.

@@ -611,7 +611,7 @@ static err_t lpc_low_level_output(struct netif *netif, struct pbuf *p)
/* Wait until enough descriptors are available for the transfer. */
/* THIS WILL BLOCK UNTIL THERE ARE ENOUGH DESCRIPTORS AVAILABLE */
#if NO_SYS == 0
for (idx = 0; idx < dn; idx++) {
for (count = 0; count < dn; count++) {

This comment has been minimized.

@kjbracey-arm

kjbracey-arm May 2, 2018

Contributor

Can you just declare it in here, please.

for (s_32_t count = 0; count < dn; count++) 

Minimise variable scopes where possible to make clear they don't have any wider significance.

This comment has been minimized.

@bmcdonnell-ionx

bmcdonnell-ionx May 2, 2018

Contributor

That is my preferred style, but I was following the style presented here. All local variables are declared at the top of the function.

That said, let me know if you still want me to make that change.

This comment has been minimized.

@kjbracey-arm

kjbracey-arm May 2, 2018

Contributor

I do like style consistency, but I like reduced-scope variables more. And as it's narrowly scoped, it has very little impact on global style...

This comment has been minimized.

@bmcdonnell-ionx

bmcdonnell-ionx May 2, 2018

Contributor

Done.

@0xc0170 0xc0170 added needs: work and removed needs: review labels May 2, 2018

@0xc0170

0xc0170 approved these changes May 3, 2018

@0xc0170

This comment has been minimized.

Member

0xc0170 commented May 3, 2018

/morph build

@0xc0170 0xc0170 added needs: CI and removed needs: work labels May 3, 2018

@mbed-ci

This comment has been minimized.

mbed-ci commented May 3, 2018

Build : SUCCESS

Build number : 1895
Build artifacts/logs : http://mbed-os.s3-website-eu-west-1.amazonaws.com/?prefix=builds/6780/

Triggering tests

/morph test
/morph uvisor-test
/morph export-build
/morph mbed2-build

@mbed-ci

This comment has been minimized.

@mbed-ci

This comment has been minimized.

@0xc0170

This comment has been minimized.

Member

0xc0170 commented May 3, 2018

/morph mbed2-build

@bmcdonnell-ionx bmcdonnell-ionx changed the title from cast to resolve compiler warning to resolve compiler warning - lpc17_emac.c May 3, 2018

@bmcdonnell-ionx bmcdonnell-ionx changed the title from resolve compiler warning - lpc17_emac.c to resolve LWIP compiler warning May 3, 2018

@0xc0170 0xc0170 merged commit 2729c7a into ARMmbed:master May 3, 2018

13 checks passed

AWS-CI uVisor Build & Test Success
Details
ci-morph-build build completed
Details
ci-morph-exporter build completed
Details
ci-morph-mbed2-build build completed
Details
ci-morph-test test completed
Details
continuous-integration/jenkins/pr-head This commit looks good
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
travis-ci/astyle Passed, 582 warnings (+0 warnings)
Details
travis-ci/docs Local docs testing has passed
Details
travis-ci/events Passed, runtime is 9190 cycles (-849 cycles)
Details
travis-ci/gitattributestest Local gitattributestest testing has passed
Details
travis-ci/littlefs Passed, code size is 10112B (+0.00%)
Details
travis-ci/tools Local tools testing has passed
Details

@0xc0170 0xc0170 removed the ready for merge label May 3, 2018

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