Skip to content

Conversation

@aggarw13
Copy link

Fix build warnings with -Wall -Wextra flags for pointer logging in MQTT files.

Description of changes:

  • Use (void *) cast for logging non-function pointers
  • Remove logging of function pointers as ISO C does not support (void *) cast of function pointers (Only POSIX does)

By submitting this pull request, I confirm that my contribution is made under the terms of the MIT license.

@codecov-commenter
Copy link

codecov-commenter commented Aug 11, 2020

Codecov Report

Merging #1109 into development will increase coverage by 1.91%.
The diff coverage is 81.48%.

Impacted file tree graph

@@               Coverage Diff               @@
##           development    #1109      +/-   ##
===============================================
+ Coverage        96.54%   98.46%   +1.91%     
===============================================
  Files                9        4       -5     
  Lines             5643     1301    -4342     
  Branches           641      385     -256     
===============================================
- Hits              5448     1281    -4167     
+ Misses               9        0       -9     
+ Partials           186       20     -166     
Impacted Files Coverage Δ
libraries/standard/mqtt/src/mqtt.c 99.46% <ø> (+5.05%) ⬆️
libraries/standard/mqtt/src/mqtt_lightweight.c 97.44% <ø> (+2.92%) ⬆️
libraries/standard/mqtt/src/mqtt_state.c 98.46% <ø> (+2.52%) ⬆️
libraries/standard/http/src/http_client.c 98.53% <81.48%> (+11.05%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 54090fb...8a0f517. Read the comment docs.

userCallback,
pTransportInterface->recv,
pTransportInterface->send ) );
LogError( ( "Invalid parameter: getTimeFunction is NULL" ) );
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the purpose in separating these parameters? It seems more repetitive this way, and it doesn't match the condition earlier in this function, at line 1374

Copy link
Author

Choose a reason for hiding this comment

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

The earlier implementation was printing the function pointers under a single if condition so that the reader could detect which of the function pointers is null. However, casting function pointers to void * for printing is not supported by ISO C.
GCC gives the following warning when casting function pointers to void *

/home/ubuntu/Repos/aws-iot-device-sdk-embedded-C/libraries/standard/mqtt/src/mqtt.c:1387:21: warning: format ‘%p’ expects argument of type ‘void *’, but argument 2 has type ‘MQTTGetCurrentTimeFunc_t {aka unsigned int (*)(void)}’ [-Wformat=]
         LogError( ( "Invalid parameter: getTimeFunction is NULL: %p", getTimeFunction ) );
                     ^
/home/ubuntu/Repos/aws-iot-device-sdk-embedded-C/demos/logging-stack/logging_stack.h:49:40: note: in definition of macro ‘SdkLog’
     #define SdkLog( string )    printf string
                                        ^~~~~~
/home/ubuntu/Repos/aws-iot-device-sdk-embedded-C/libraries/standard/mqtt/src/mqtt.c:1387:9: note: in expansion of macro ‘LogError’
         LogError( ( "Invalid parameter: getTimeFunction is NULL: %p", getTimeFunction ) );

@aggarw13 aggarw13 merged commit a5894f8 into aws:development Aug 12, 2020
@aggarw13 aggarw13 deleted the hygiene/fix-pointer-logging-warnings branch August 12, 2020 21:32
yourslab pushed a commit to yourslab/aws-iot-device-sdk-embedded-C that referenced this pull request Aug 17, 2020
leegeth pushed a commit to leegeth/aws-iot-device-sdk-embedded-C that referenced this pull request Aug 27, 2020
leegeth pushed a commit to leegeth/aws-iot-device-sdk-embedded-C that referenced this pull request Aug 28, 2020
leegeth pushed a commit to leegeth/aws-iot-device-sdk-embedded-C that referenced this pull request Aug 31, 2020
leegeth pushed a commit to leegeth/aws-iot-device-sdk-embedded-C that referenced this pull request Sep 1, 2020
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