Changeset dd0502ae in mainline for uspace/lib/c/test/strtol.c


Ignore:
Timestamp:
2019-05-27T16:18:02Z (5 years ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
1c9bf292
Parents:
0260034
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2019-05-27 15:58:34)
git-committer:
Jiří Zárevúcky <zarevucky.jiri@…> (2019-05-27 16:18:02)
Message:

Add test for negative input to strtoul()

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/test/strtol.c

    r0260034 rdd0502ae  
    3838#include <stdlib.h>
    3939#include <str.h>
     40#include <limits.h>
    4041
    4142PCUT_INIT;
     
    249250}
    250251
     252PCUT_TEST(strtoul_negative_wraparound)
     253{
     254        long output;
     255        char *endp;
     256        char *endp_unchanged = (char *) "endp_unchanged unique pointer";
     257        int errno_unchanged = -1;
     258        const char *input;
     259        int base;
     260
     261        /*
     262         * N2176 7.22.1.4 The strtol, strtoll, strtoul, and strtoull functions
     263         *
     264         * "If the subject sequence begins with a minus sign, the value
     265         * resulting from the conversion is negated (in the return type)."
     266         */
     267
     268        endp = endp_unchanged;
     269        errno = errno_unchanged;
     270        output = strtoul(input = "-10", &endp, base = 0);
     271        PCUT_ASSERT_INT_EQUALS(errno_unchanged, errno);
     272        PCUT_ASSERT_PTR_EQUALS(input + 3, endp);
     273        PCUT_ASSERT_UINT_EQUALS(-(10ul), output);
     274}
     275
    251276PCUT_TEST(strtol_fringe)
    252277{
Note: See TracChangeset for help on using the changeset viewer.