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

lint: _sbrk_r: change parameter type from size_t to ptrdiff_t #1664

Merged
merged 1 commit into from
Sep 14, 2014

Conversation

N8Fear
Copy link

@N8Fear N8Fear commented Sep 14, 2014

incr is of type size_t which is essentially a unsigned int type (according to ISO 1999 C it's an unsigned integer of at least 16 Bit). Since unsigned integers can't be smaller than zero the check is unnecessary (and will hopefully gets optimized away by the compiler anyways).
This PR removes the unnecessary check to silence cppcheck.
This PR changes the type of incr to ptrdiff_t (as suggested by @Kijewski ).
Added: changed this for _sbrk_r implementations for other platforms too.

@N8Fear N8Fear added the Type: cleanup The issue proposes a clean-up / The PR cleans-up parts of the codebase / documentation label Sep 14, 2014
@@ -75,13 +75,6 @@ void __assert(const char *file, int line, const char *failedexpr)
/*-----------------------------------------------------------------------------------*/
caddr_t _sbrk_r(struct _reent *r, size_t incr)
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess the parameter type for incr is wrong. It should take a ptrdiff_t

@N8Fear N8Fear force-pushed the unsignedLessThanZero branch from 9ad6a68 to d126eb1 Compare September 14, 2014 12:56
@N8Fear
Copy link
Author

N8Fear commented Sep 14, 2014

Changed PR to use ptrdiff_t.

@OlegHahm
Copy link
Member

Newlib uses ptrdiff_t, too. Can you change the prototypes for the other platforms, too?

cpu/lpc_common/lpc_syscalls.c:caddr_t _sbrk_r(struct _reent *r, size_t incr)
cpu/mc1322x/mc1322x_syscalls.c:caddr_t _sbrk_r(struct _reent *r, size_t incr)
cpu/nrf51822/syscalls.c:caddr_t _sbrk_r(struct _reent *r, size_t incr)
cpu/sam3x8e/syscalls.c:caddr_t _sbrk_r(struct _reent *r, size_t incr)
cpu/stm32f0/syscalls.c:caddr_t _sbrk_r(struct _reent *r, size_t incr)
cpu/stm32f1/syscalls.c:caddr_t _sbrk_r(struct _reent *r, size_t incr)
cpu/stm32f3/syscalls.c:caddr_t _sbrk_r(struct _reent *r, size_t incr)
cpu/stm32f4/syscalls.c:caddr_t _sbrk_r(struct _reent *r, size_t incr)

@N8Fear N8Fear force-pushed the unsignedLessThanZero branch from d126eb1 to 129e9b0 Compare September 14, 2014 20:07
@N8Fear
Copy link
Author

N8Fear commented Sep 14, 2014

@OlegHahm: done.
Should I change the title of this PR to reflect this?

@OlegHahm
Copy link
Member

Thanks. Changing the title sounds sensible to me.

@N8Fear N8Fear changed the title lint: remove check for value less than zero on unsigned var lint: _sbrk_r: change parameter type from size_t to ptrdiff_t Sep 14, 2014
@Kijewski
Copy link
Contributor

ACK.

Kijewski added a commit that referenced this pull request Sep 14, 2014
lint: _sbrk_r: change parameter type from size_t to ptrdiff_t
@Kijewski Kijewski merged commit ba07d6a into RIOT-OS:master Sep 14, 2014
@N8Fear N8Fear deleted the unsignedLessThanZero branch September 14, 2014 21:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: cleanup The issue proposes a clean-up / The PR cleans-up parts of the codebase / documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants