canhardware: remove ambiguous 2-arg Send overload (lets callers drop uint8_t casts)#56
Merged
jsphuebner merged 1 commit intoJun 21, 2026
Conversation
The forceExt-defaulted 2-arg convenience void Send(uint32_t canId, uint32_t data[2], bool forceExt = false) makes a 3-arg call Send(id, uint32_t* data, intLen) ambiguous: the int length matches both this (int->bool) and the length overload (int->uint8_t), so callers must cast the length to uint8_t. Nothing passes forceExt through this 2-arg form - within libopeninv it is carried via the canId CAN_FORCE_EXTENDED bit, and all internal Send calls use the 2-arg or uint8_t-length forms. Drop the bool: Send(id, data) still sends 8 bytes, forceExt stays available via the 4-arg Send(id, data, len, true), and Send(id, u32buf, len) now resolves unambiguously to the length overload - no uint8_t cast needed.
wjcloudy
marked this pull request as ready for review
June 20, 2026 20:27
Owner
|
Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The
forceExt-defaulted 2-arg convenience overloadmakes a 3-arg call
Send(id, uint32_t* data, intLen)ambiguous — theintlength matches both this overload (int→bool) and the length overload (int→uint8_t). Downstream projects then have to cast every length touint8_t:This came up in damienmaguire/Stm32-vcu#239 when bumping Stm32-vcu to current libopeninv (~76 call sites needed casts).
Fix
Drop the
bool forceExtfrom the 2-arguint32_tconvenience. Nothing actually passesforceExtthrough this form — inside libopeninv it's carried via the canIdCAN_FORCE_EXTENDEDbit, and all internalSendcalls use the 2-arg oruint8_t-length forms.Send(id, data)still sends 8 bytes (unchanged).Send(id, data, len, true).Send(id, u32buf, len)now resolves unambiguously to the length overload — no cast needed.Verified — no consumer uses the dropped form
CAN_FORCE_EXTENDEDbit; all internalSendcalls use the 2-arg oruint8_t-length forms.Send()calls at all (CAN output goes throughCanMap/CanSdo), so it's unaffected.(uint8_t)casts can be removed andSend(id, u32buf, 8)compiles cleanly.Draft — happy to adjust if you'd prefer a different approach (e.g. widening the
lentype instead of dropping the overload).