owntone / owntone-server

Linux/FreeBSD DAAP (iTunes) and MPD media server with support for AirPlay 1 and 2 speakers (multiroom), Apple Remote (and compatibles), Chromecast, Spotify and internet radio.
https://owntone.github.io/owntone-server
GNU General Public License v2.0
1.99k stars 227 forks source link

[code] Linting C source code #1750

Closed hacketiwack closed 1 month ago

hacketiwack commented 1 month ago

While I was playing around with the cppcheck and scan-build commands, I came across a few "issues" in the code. As I'm not a C programmer, these issues might not be real issues.

Hereafter is the result of the cppcheck --force command:

src/httpd_daap.c:2237:7: error: Address of local auto-variable assigned to a function parameter. [autoVariables]
      hreq->extra_data = &session;
      ^
src/httpd_jsonapi.c:528:16: error: Boolean value assigned to pointer. [assignBoolToPointer]
      notfound = false;
               ^
src/outputs/cast.c:416:188: error: There is an unknown macro here somewhere. Configuration is required. If NTOSTR is a macro then please configure it. [unknownMacro]
    .payload = "{'type':'OFFER','seqNum':%u,'offer':{'castMode':'mirroring','supportedStreams':[{'index':0,'type':'audio_source','codecName':'opus','rtpProfile':'cast','rtpPayloadType':" NTOSTR(CAST_RTP_PAYLOADTYPE_AUDIO) ",'ssrc':%" PRIu32 ",'storeTime':400,'targetDelay':400,'bitRate':128000,'sampleRate':" NTOSTR(CAST_QUALITY_SAMPLE_RATE_DEFAULT) ",'timeBase':'1/" NTOSTR(CAST_QUALITY_SAMPLE_RATE_DEFAULT) "','channels':" NTOSTR(CAST_QUALITY_CHANNELS_DEFAULT) ",'receiverRtcpEventLog':false},{'codecName':'vp8','index':1,'maxBitRate':5000000,'maxFrameRate':'30000/1000','receiverRtcpEventLog':false,'renderMode':'video','resolutions':[{'height':900,'width':1600}],'rtpPayloadType':" NTOSTR(CAST_RTP_PAYLOADTYPE_VIDEO) ",'rtpProfile':'cast','ssrc':999999,'targetDelay':400,'timeBase':'1/90000','type':'video_source'}]}}",
                                                                                                                                                                                           ^
src/pair_ap/pair.c:95:1: error: Found a exit path from function with non-void return type that has missing return statement [missingReturn]
}
^
src/pair_ap/pair.c:115:1: error: Found a exit path from function with non-void return type that has missing return statement [missingReturn]
}
^
src/pair_ap/pair.c:140:1: error: Found a exit path from function with non-void return type that has missing return statement [missingReturn]
}
^
src/pair_ap/pair.c:160:1: error: Found a exit path from function with non-void return type that has missing return statement [missingReturn]
}
^
src/pair_ap/pair.c:179:1: error: Found a exit path from function with non-void return type that has missing return statement [missingReturn]
}
^
src/pair_ap/pair_fruit.c:507:1: error: Found a exit path from function with non-void return type that has missing return statement [missingReturn]
}
^
src/pair_ap/pair_fruit.c:590:1: error: Found a exit path from function with non-void return type that has missing return statement [missingReturn]
}
^

The result of the command scan-build is a bit more verbose and is available here.

ejurgensen commented 1 month ago

Thanks, I've gone through them, and I think there was one actual bug, which is the boolean value assigned to a pointer. Then there was a missing include, which I also fixed.

The scan-build records are all about assigning values to variables without reading from them. While it's obviously superfluous, it can make sense on order for the code to be consistent. I suggest you disable that check as it is in the Github action workflow.