Skip to content
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

Fix compiler warnings #75

Merged
merged 34 commits into from
Sep 5, 2020

Conversation

yan-foto
Copy link
Contributor

As discussed in #74 here is a set of changes that fix compiler warnings. Some of the changes are trivial and non-critical while the others fix some hidden bugs such as missing return statements and possibly unsafe pointer arithmetic.

Each commit addresses a specific warning type and additional information (if applicable) is also included in commit message.

Hanwen Zhang and others added 21 commits January 10, 2020 15:44
Changes fix following errors:
- encode/signed-interest.c:298:24: warning: comparison of integer expressions of different signedness: ‘size_t’ {aka ‘unsigned int’} and ‘int’
- encode/signed-interest.c:347:24: warning: comparison of integer expressions of different signedness: ‘size_t’ {aka ‘unsigned int’} and ‘int’
- encode/signed-interest.c:395:24: warning: comparison of integer expressions of different signedness: ‘size_t’ {aka ‘unsigned int’} and ‘int’
- encode/wrapper-api.c:256:17: warning: comparison of integer expressions of different signedness: ‘uint32_t’ {aka ‘unsigned int’} and ‘int’
- encode/wrapper-api.c:670:17: warning: comparison of integer expressions of different signedness: ‘uint32_t’ {aka ‘unsigned int’} and ‘int’
- forwarder/name-tree.c:88:17: warning: comparison of integer expressions of different signedness: ‘int’ and ‘size_t’ {aka ‘unsigned int’}
- forwarder/name-tree.c:117:17: warning: comparison of integer expressions of different signedness: ‘int’ and ‘size_t’ {aka ‘unsigned int’}
- forwarder/name-tree.c:168:17: warning: comparison of integer expressions of different signedness: ‘int’ and ‘size_t’ {aka ‘unsigned int’}

NOTE: some changes are just removal of white spaces (automatically
applied by my IDE).
Changes fix following error:
- encode/wrapper-api.c:405:12: warning: this statement may fall through [-Wimplicit-fallthrough=]
Changes fix following warnings:
- encode/encrypted-payload.c:117:23: warning: format ‘%ld’ expects argument of type ‘long int’, but argument 2 has type ‘uint32_t’ {aka ‘unsigned int’}
- encode/encrypted-payload.c:117:23: warning: format ‘%ld’ expects argument of type ‘long int’, but argument 3 has type ‘uint32_t’ {aka ‘unsigned int’}
Changes fix following errors:
- security/ndn-lite-hmac.c:146:18: warning: comparison of unsigned
expression < 0 is always false (3 errors on the same line)
Changes fix following errors:
- encode/key-storage.c:126:1: error: old-style function definition
- encode/key-storage.c:156:1: error: old-style function definition
Changes fixes following warnings:
- forwarder/forwarder.c:314:1: error: control reaches end of non-void function
Changes fix following warnings:
- forwarder/forwarder.c:311:37: error: passing argument 2 of ‘ndn_interest_tlv_encode’ discards ‘const’ qualifier from pointer target type

NOTE: the cause of this warning is 'ndn_interest_tlv_encode' in
which name components are updated to cater for a SHA256 digest.
Changes fix following warnings:
- forwarder/name-tree.c:83:17: error: variable ‘last_node’ set but not used

NOTE: this unused variable seems to be remainder of a 'copy/paste'
action!
Changes fix following warnings:
- encode/name-component.c:30:10: error: 'result' may be used uninitialized in this function [-Werror=maybe-uninitialized]
- encode/../util/logger.h:25:3: error: 'keyid' may be used uninitialized in this function

NOTE: this error occures only in older compilers that are not smart
enough to understand that the uninitialized vale are filled out
later.
@yan-foto yan-foto force-pushed the feature/warnings-fix branch from 4847b10 to ae85f84 Compare August 27, 2020 16:48
@yan-foto
Copy link
Contributor Author

I still get a number of unused-parameter warnings which I have postponed for the future. Maybe you guys can take a look at them.

@yoursunny
Copy link
Contributor

It’s necessary to have continuous integration that turns on -Werror to ensure these warnings do not reappear.
Warnings that have not been fixed can then be turned off via -Wno-error=unused-parameter.

git-subtree-dir: tests
git-subtree-mainline: ae85f84
git-subtree-split: 0a9954d
In previous structure, NDN lite tests were in their own repository
with NDN lite sources as a submodule in base directory. Here, the
relationship is inverse, i.e., the tests are integrated directly in
NDN lite repository.

In this commit a really cheap trick (symlink to parent instead of
submodule) is used to have the tests running without changing the
source code. This might need some reconsideration in the future!
@yoursunny
Copy link
Contributor

yoursunny commented Sep 1, 2020

I tested f0998b4 on Ubuntu 16.04 using GCC 5.4.0.

I'm still seeing warnings (that do not belong in test files). For example:

/tmp/ndn-lite/tests/ndn-lite/app-support/access-control.c: In function ‘_on_ac_notification’:
/tmp/ndn-lite/tests/ndn-lite/app-support/access-control.c:141:22: warning: passing argument 1 of ‘ndn_name_print’ from incompatible pointer type [-Wincompatible-pointer-types]
   NDN_LOG_DEBUG_NAME(&notification);
                      ^
/tmp/ndn-lite/tests/ndn-lite/app-support/../util/logger.h:41:18: note: in definition of macro ‘NDN_LOG_DEBUG_NAME’
   ndn_name_print(name);\
                  ^
In file included from /tmp/ndn-lite/tests/ndn-lite/app-support/../encode/interest.h:14:0,
                 from /tmp/ndn-lite/tests/ndn-lite/app-support/access-control.h:14,
                 from /tmp/ndn-lite/tests/ndn-lite/app-support/access-control.c:11:
/tmp/ndn-lite/tests/ndn-lite/app-support/../encode/name.h:42:1: note: expected ‘const ndn_name_t * {aka const struct ndn_name *}’ but argument is of type ‘ndn_interest_t * {aka struct ndn_interest *}’
 ndn_name_print(const ndn_name_t* name);
 ^
In file included from /tmp/ndn-lite/tests/ndn-lite/app-support/access-control.c:30:0:
/tmp/ndn-lite/tests/ndn-lite/app-support/access-control.c:149:21: warning: format ‘%lu’ expects argument of type ‘long unsigned int’, but argument 3 has type ‘uint32_t {aka unsigned int}’ [-Wformat=]
       NDN_LOG_DEBUG("[ACCESSCTL] Enforced update for Service %u, KeyID %lu\n",
                     ^
/tmp/ndn-lite/tests/ndn-lite/app-support/../util/logger.h:38:10: note: in definition of macro ‘NDN_LOG_DEBUG’
   printf(__VA_ARGS__); \
          ^
/tmp/ndn-lite/tests/ndn-lite/app-support/access-control.c: In function ‘_on_ekey_data’:
/tmp/ndn-lite/tests/ndn-lite/app-support/access-control.c:208:17: warning: format ‘%lu’ expects argument of type ‘long unsigned int’, but argument 2 has type ‘uint32_t {aka unsigned int}’ [-Wformat=]
   NDN_LOG_DEBUG("[ACCESSCTL] AES KeyID = %lu \n", keyid);
                 ^
/tmp/ndn-lite/tests/ndn-lite/app-support/../util/logger.h:38:10: note: in definition of macro ‘NDN_LOG_DEBUG’
   printf(__VA_ARGS__); \
          ^
/tmp/ndn-lite/tests/ndn-lite/app-support/access-control.c:253:17: warning: format ‘%llu’ expects argument of type ‘long long unsigned int’, but argument 2 has type ‘ndn_time_us_t {aka long unsigned int}’ [-Wformat=]
   NDN_LOG_DEBUG("[ACCESSCTL] Key update: %lluus\n", m_measure_tp2 - m_measure_t
                 ^
/tmp/ndn-lite/tests/ndn-lite/app-support/../util/logger.h:38:10: note: in definition of macro ‘NDN_LOG_DEBUG’
   printf(__VA_ARGS__); \
          ^
/tmp/ndn-lite/tests/ndn-lite/app-support/access-control.c: In function ‘_on_dkey_data’:
/tmp/ndn-lite/tests/ndn-lite/app-support/access-control.c:308:17: warning: format ‘%lu’ expects argument of type ‘long unsigned int’, but argument 2 has type ‘uint32_t {aka unsigned int}’ [-Wformat=]
   NDN_LOG_DEBUG("[ACCESSCTL] AES KeyID = %lu \n", keyid);
                 ^
/tmp/ndn-lite/tests/ndn-lite/app-support/../util/logger.h:38:10: note: in definition of macro ‘NDN_LOG_DEBUG’
   printf(__VA_ARGS__); \
          ^
/tmp/ndn-lite/tests/ndn-lite/app-support/access-control.c: In function ‘_express_ekey_interest’:
/tmp/ndn-lite/tests/ndn-lite/app-support/access-control.c:394:35: warning: initialization from incompatible pointer type [-Wincompatible-pointer-types]
   ndn_name_t* self_identity_key = ndn_key_storage_get_self_identity_key(service
                                   ^
/tmp/ndn-lite/tests/ndn-lite/app-support/access-control.c:399:60: warning: passing argument 3 of ‘ndn_signed_interest_ecdsa_sign’ from incompatible pointer type [-Wincompatible-pointer-types]
   ndn_signed_interest_ecdsa_sign(&interest, self_identity, self_identity_key);
                                                            ^
In file included from /tmp/ndn-lite/tests/ndn-lite/app-support/access-control.c:15:0:
/tmp/ndn-lite/tests/ndn-lite/app-support/../encode/signed-interest.h:43:1: note: expected ‘const ndn_ecc_prv_t * {aka const struct ndn_ecc_prv *}’ but argument is of type ‘ndn_name_t * {aka struct ndn_name *}’
 ndn_signed_interest_ecdsa_sign(ndn_interest_t* interest,
 ^
In file included from /tmp/ndn-lite/tests/ndn-lite/app-support/access-control.c:30:0:
/tmp/ndn-lite/tests/ndn-lite/app-support/access-control.c: In function ‘ndn_ac_trigger_expiration’:
/tmp/ndn-lite/tests/ndn-lite/app-support/access-control.c:577:19: warning: format ‘%ld’ expects argument of type ‘long int’, but argument 2 has type ‘uint32_t {aka unsigned int}’ [-Wformat=]
     NDN_LOG_DEBUG("[ACCESSCTL] Local Decryption Key %ld forced expired\n", aes_
                   ^
/tmp/ndn-lite/tests/ndn-lite/app-support/../util/logger.h:38:10: note: in definition of macro ‘NDN_LOG_DEBUG’
   printf(__VA_ARGS__); \
          ^
/tmp/ndn-lite/tests/ndn-lite/app-support/access-control.c:581:19: warning: format ‘%ld’ expects argument of type ‘long int’, but argument 2 has type ‘uint32_t {aka unsigned int}’ [-Wformat=]
     NDN_LOG_DEBUG("[ACCESSCTL] Notifying Encryption Key %ld forced expired\n",
                   ^
/tmp/ndn-lite/tests/ndn-lite/app-support/../util/logger.h:38:10: note: in definition of macro ‘NDN_LOG_DEBUG’
   printf(__VA_ARGS__); \
          ^
/tmp/ndn-lite/tests/ndn-lite/app-support/access-control.c: In function ‘_on_ac_notification’:
/tmp/ndn-lite/tests/ndn-lite/app-support/access-control.c:158:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
/tmp/ndn-lite/tests/ndn-lite/app-support/access-control.c: In function ‘ndn_ac_trigger_expiration’:
/tmp/ndn-lite/tests/ndn-lite/app-support/access-control.c:599:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^

The proper way to resolve -Wformat is to #include <inttypes.h> and then use PRIu64 etc.
For things like ndn_time_us_t, add a #define PRI_ndn_time_us_t PRIu64 right next to the typedef declaring that type, then use PRI_ndn_time_us_t macro when you need to print a value of that type.

@yan-foto
Copy link
Contributor Author

yan-foto commented Sep 1, 2020 via email

Changes here make format strings portable and cross platform
compatible.
Copy link
Contributor

@yoursunny yoursunny left a comment

Choose a reason for hiding this comment

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

/tmp/ndn-lite/tests/ndn-lite/app-support/security-bootstrapping.c: In function ‘sec_boot_send_cert_interest’:
/tmp/ndn-lite/tests/ndn-lite/app-support/security-bootstrapping.c:286:46: error: passing argument 5 of ‘ndn_forwarder_express_interest’ discards ‘const’ qualifier from pointer target type [-Werror=discarded-qualifiers]
                                              &m_sec_boot_state.device_info->ser
                                              ^
In file included from /tmp/ndn-lite/tests/ndn-lite/app-support/security-bootstrapping.h:16:0,
                 from /tmp/ndn-lite/tests/ndn-lite/app-support/security-bootstrapping.c:11:
/tmp/ndn-lite/tests/ndn-lite/app-support/../forwarder/forwarder.h:167:1: note: expected ‘void *’ but argument is of type ‘const uint8_t * const {aka const unsigned char * const}’
 ndn_forwarder_express_interest(uint8_t* interest, size_t length,
 ^

@yan-foto
Copy link
Contributor Author

yan-foto commented Sep 3, 2020

My time is really tight here. I'd appreciate it if the last mile can be taken care of by the core team.

@yoursunny this is exactly what I'm talking about 👆

@yoursunny
Copy link
Contributor

I'd appreciate it if the last mile can be taken care of by the core team.

I think you are a better developer than most others, and you deserve a spot on the core team or become the project manager.

@tianyuan129
Copy link
Member

I can change this quickly, but could you take a look at the rest?

sure, can I merge it first your project can move on?

@yoursunny
Copy link
Contributor

sure, can I merge it first your project can move on?

I'd recommend not to merge the current code, since it leaves the codebase in an uncompilable state.
All warnings have to be resolved.

@yan-foto
Copy link
Contributor Author

yan-foto commented Sep 3, 2020

I think you are a better developer than most others, and you deserve a spot on the core team or become the project manager.

you should've been a politician or at least be awarded with a medal or something for your convincing skills :)

sure, can I merge it first your project can move on?

Thanks for the offer, but let's wait until everything is resolved. @yoursunny somehow convinced me to do take care of the rest...

Changes fix following errors:
- ndn-lite/app-support/security-bootstrapping.c:286:46: error: passing argument 5 of ‘ndn_forwarder_express_interest’ discards ‘const’ qualifier from pointer target type

NOTE: This specific error was caused by inconsistend programming in
declaring a pointer as const in one place but assigning it to other
pointers which are not const.
Changes fix following warnings:
- adaptation/udp/udp-face.c:206:7: error: variable ‘ret’ set but not used

NOTE: it seems that original authors abruptly stopped coding...
Changes fix follwoing warnings:
- tests/adaptation/security/ndn-lite-rng-posix-crypto-impl.c:31:18: error: implicit declaration of function ‘read’; did you mean ‘creat’?
@yan-foto
Copy link
Contributor Author

yan-foto commented Sep 4, 2020

So the warnings are fixed and the tests all pass. During this process I also discovered some bugs which makes me really wonder why these were not flagged by the unit tests 🤔

Anyhow, it has been a while since I've used Travis CI on GitHub and according to [its docs] you should first enable it for GitHub before using it. If I understand it correctly, it doesn't pick up jobs automatically anymore as it used to do. Nonetheless I added a preliminary CI script, wondering if it's gonna work!

@yoursunny
Copy link
Contributor

you should first enable it for GitHub before using it

For Travis CI, you need to enable it on your fork first.
Independently, a maintainer needs to enable it for this repository.

Copy link
Contributor

@yoursunny yoursunny left a comment

Choose a reason for hiding this comment

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

I can confirm there's no more warning on Ubuntu 16.04 with GCC.
Travis script is the only problem. @yan-foto needs to enable Travis on his fork to confirm the result.

.travis.yml Outdated Show resolved Hide resolved
.travis.yml Show resolved Hide resolved
.travis.yml Show resolved Hide resolved
@yan-foto yan-foto force-pushed the feature/warnings-fix branch 2 times, most recently from 739f305 to 383db5a Compare September 5, 2020 09:50
@yan-foto yan-foto force-pushed the feature/warnings-fix branch from 383db5a to 3bb4bdc Compare September 5, 2020 09:56
@yan-foto
Copy link
Contributor Author

yan-foto commented Sep 5, 2020

OK folks, everything works as expected. I really didn't want to work on shabbat, but I guess I also couldn't leave this cake half-baked!

The unit tests pass but I still think the code needs more rigorous testing. So maybe we first merge this on the develop branch and have it tested by some of our best (students). What do you reckon?

@tianyuan129 tianyuan129 changed the base branch from master to develop September 5, 2020 10:21
@tianyuan129 tianyuan129 merged commit a44bda3 into named-data-iot:develop Sep 5, 2020
@yoursunny
Copy link
Contributor

@tianyuan129 needs to install Travis CI in this repository.

@tianyuan129
Copy link
Member

Sure. Currently I'm not the admin for this repository. Let me ask for the permission first and then I'll install it.

@yoursunny
Copy link
Contributor

@Zhiyi-Zhang needs to install Travis CI in this repository.

@tianyuan129
Copy link
Member

just installed Travis CI on develop branch: d60a114.

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.

4 participants