Changeset 8e893ae in mainline


Ignore:
Timestamp:
2012-04-07T17:49:43Z (12 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
c7afcba7
Parents:
a4a0f1d
Message:

avoid comparison with 0 if the type is unsigned

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • boot/generic/src/str.c

    ra4a0f1d r8e893ae  
    100100#include <str.h>
    101101#include <errno.h>
     102
     103/** Check the condition if wchar_t is signed */
     104#ifdef WCHAR_IS_UNSIGNED
     105        #define WCHAR_SIGNED_CHECK(cond)  (true)
     106#else
     107        #define WCHAR_SIGNED_CHECK(cond)  (cond)
     108#endif
    102109
    103110/** Byte mask consisting of lowest @n bits (out of 8) */
     
    198205 *         code was invalid.
    199206 */
    200 int chr_encode(wchar_t ch, char *str, size_t *offset, size_t size)
     207int chr_encode(const wchar_t ch, char *str, size_t *offset, size_t size)
    201208{
    202209        if (*offset >= size)
     
    325332bool ascii_check(wchar_t ch)
    326333{
    327         if ((ch >= 0) && (ch <= 127))
     334        if (WCHAR_SIGNED_CHECK(ch >= 0) && (ch <= 127))
    328335                return true;
    329336       
     
    338345bool chr_check(wchar_t ch)
    339346{
    340         if ((ch >= 0) && (ch <= 1114111))
     347        if (WCHAR_SIGNED_CHECK(ch >= 0) && (ch <= 1114111))
    341348                return true;
    342349       
  • kernel/generic/src/lib/str.c

    ra4a0f1d r8e893ae  
    111111#include <debug.h>
    112112#include <macros.h>
     113
     114/** Check the condition if wchar_t is signed */
     115#ifdef WCHAR_IS_UNSIGNED
     116        #define WCHAR_SIGNED_CHECK(cond)  (true)
     117#else
     118        #define WCHAR_SIGNED_CHECK(cond)  (cond)
     119#endif
    113120
    114121/** Byte mask consisting of lowest @n bits (out of 8) */
     
    206213 *
    207214 * @return EOK if the character was encoded successfully, EOVERFLOW if there
    208  *         was not enough space in the output buffer or EINVAL if the character
    209  *         code was invalid.
    210  */
    211 int chr_encode(wchar_t ch, char *str, size_t *offset, size_t size)
     215 *         was not enough space in the output buffer or EINVAL if the character
     216 *         code was invalid.
     217 */
     218int chr_encode(const wchar_t ch, char *str, size_t *offset, size_t size)
    212219{
    213220        if (*offset >= size)
     
    427434bool ascii_check(wchar_t ch)
    428435{
    429         if ((ch >= 0) && (ch <= 127))
     436        if (WCHAR_SIGNED_CHECK(ch >= 0) && (ch <= 127))
    430437                return true;
    431438       
     
    440447bool chr_check(wchar_t ch)
    441448{
    442         if ((ch >= 0) && (ch <= 1114111))
     449        if (WCHAR_SIGNED_CHECK(ch >= 0) && (ch <= 1114111))
    443450                return true;
    444451       
  • uspace/lib/c/generic/str.c

    ra4a0f1d r8e893ae  
    4646#include <mem.h>
    4747#include <str.h>
     48
     49/** Check the condition if wchar_t is signed */
     50#ifdef WCHAR_IS_UNSIGNED
     51        #define WCHAR_SIGNED_CHECK(cond)  (true)
     52#else
     53        #define WCHAR_SIGNED_CHECK(cond)  (cond)
     54#endif
    4855
    4956/** Byte mask consisting of lowest @n bits (out of 8) */
     
    399406bool ascii_check(wchar_t ch)
    400407{
    401         if ((ch >= 0) && (ch <= 127))
     408        if (WCHAR_SIGNED_CHECK(ch >= 0) && (ch <= 127))
    402409                return true;
    403410       
     
    412419bool chr_check(wchar_t ch)
    413420{
    414         if ((ch >= 0) && (ch <= 1114111))
     421        if (WCHAR_SIGNED_CHECK(ch >= 0) && (ch <= 1114111))
    415422                return true;
    416423       
     
    513520 * @param count Size of the destination buffer (must be > 0).
    514521 * @param src   Source string.
     522 *
    515523 */
    516524void str_cpy(char *dest, size_t size, const char *src)
     
    545553 * @param src   Source string.
    546554 * @param n     Maximum number of bytes to read from @a src.
     555 *
    547556 */
    548557void str_ncpy(char *dest, size_t size, const char *src, size_t n)
Note: See TracChangeset for help on using the changeset viewer.