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

Plt/nanocbor fixes for wextra #2

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/nanocbor/nanocbor.h
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ void nanocbor_decoder_init(nanocbor_value_t *value,
* @return major type
* @return NANOCBOR_ERR_END if the buffer is exhausted
*/
int nanocbor_get_type(const nanocbor_value_t *value);
size_t nanocbor_get_type(const nanocbor_value_t *value);

/**
* @brief Check if the current buffer or container is exhausted
Expand Down
14 changes: 8 additions & 6 deletions src/decoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ bool nanocbor_at_end(const nanocbor_value_t *it)
return end;
}

int nanocbor_get_type(const nanocbor_value_t *value)
size_t nanocbor_get_type(const nanocbor_value_t *value)
{
if (nanocbor_at_end(value)) {
return NANOCBOR_ERR_END;
Expand Down Expand Up @@ -121,12 +121,14 @@ static int _get_uint64(const nanocbor_value_t *cvalue, uint32_t *value, uint_lea
return NANOCBOR_ERR_END;
}
uint64_t tmp = 0;
uint_fast64_t val64;
/* Copy the value from cbor to the least significant bytes */
memcpy(((uint_least8_t *)&tmp) + sizeof(uint64_t) - bytes, cvalue->cur + 1U, bytes);
/* NOLINTNEXTLINE: user supplied function */
tmp = NANOCBOR_BE64TOH_FUNC(tmp);
*value = 0;
memcpy(value, &tmp, bytes);
/* for-loop to handle excotic cpu arthitectures, eg. no 8-bit support*/
for (uint_fast8_t i = 0; i < bytes; i++) {
val64 = 0x00000000000000ffull & *((uint_fast8_t*)(cvalue->cur + 1 + i));
tmp |= ( val64<<(8 * (bytes - i - 1)) );
}
*value = tmp;

return (int)(1 + bytes);
}
Expand Down