Skip to content
Merged
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 .default-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0
1.0.1
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
sudo apt-get -y install autoconf automake libtool

- name: Checkout
uses: actions/checkout@v3.5.3
uses: actions/checkout

- name: Bootstrap and Configure
run: |
Expand All @@ -63,7 +63,7 @@ jobs:
- name: Test
run: |
make -j check
- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact
if: ${{ failure() }}
with:
name: test-libstrntoul-log
Expand All @@ -90,7 +90,7 @@ jobs:
steps:

- name: Checkout
uses: actions/checkout@v3.5.3
uses: actions/checkout

- name: Install Dependencies
run: |
Expand Down
10 changes: 8 additions & 2 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
# Changes and What's New in strntoul

#### 1.0.1 (2026-04-04)

* Addresses an issue with single digit conversion of zero ('0') that should
succeed with both `strntol` and `strtoul`.

#### 1.0.0 (2024-02-28)

* Initial public release independent of [OpenHLX](https://github.com/gerickson/openhlx/), from which [these
sources came](https://github.com/gerickson/openhlx/tree/main/src/lib/utilities).
* Initial public release independent of [OpenHLX]
(https://github.com/gerickson/openhlx/), from which [these sources came]
(https://github.com/gerickson/openhlx/tree/main/src/lib/utilities).

4 changes: 4 additions & 0 deletions src/strntoul.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ HandleBase(const char *&aString, const size_t &aLength, const int &aBase)
}
else
{
// Back up so the leading '0' is available to the
// conversion loop as a valid octal (or decimal) digit.

aString--;
lRetval = 8;
}
}
Expand Down
58 changes: 55 additions & 3 deletions src/tests/Test_strntol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,45 @@ static void TestImplicitBase(nlTestSuite *inSuite __attribute__((unused)),
char * lEnd;


// 1: Test octal (8)
// 1: Test bare zero with implicit base

// 1.1: A bare "0" with implicit base should parse as the value
// zero (0), not be consumed as an octal prefix with no
// digits following.

errno = 0;
lString = "0";
lLength = strlen(lString);

lResult = strntol(lString, lLength, &lEnd, kBase);
NL_TEST_ASSERT(inSuite, lResult == 0);
NL_TEST_ASSERT(inSuite, lEnd == lString + lLength);
NL_TEST_ASSERT(inSuite, errno == 0);

// 1.2: A bare "00" with implicit base should parse as zero (0)
// in octal and consume both characters.

errno = 0;
lString = "00";
lLength = strlen(lString);

lResult = strntol(lString, lLength, &lEnd, kBase);
NL_TEST_ASSERT(inSuite, lResult == 0);
NL_TEST_ASSERT(inSuite, lEnd == lString + lLength);
NL_TEST_ASSERT(inSuite, errno == 0);

// 1.3: "01" with implicit base should parse as octal 1.

errno = 0;
lString = "01";
lLength = strlen(lString);

lResult = strntol(lString, lLength, &lEnd, kBase);
NL_TEST_ASSERT(inSuite, lResult == 1);
NL_TEST_ASSERT(inSuite, lEnd == lString + lLength);
NL_TEST_ASSERT(inSuite, errno == 0);

// 2: Test octal (8)

errno = 0;
lString = "007";
Expand All @@ -156,7 +194,7 @@ static void TestImplicitBase(nlTestSuite *inSuite __attribute__((unused)),
NL_TEST_ASSERT(inSuite, lEnd == lString + lLength);
NL_TEST_ASSERT(inSuite, errno == 0);

// 2: Test decimal (10)
// 3: Test decimal (10)

errno = 0;
lString = "13";
Expand All @@ -176,7 +214,7 @@ static void TestImplicitBase(nlTestSuite *inSuite __attribute__((unused)),
NL_TEST_ASSERT(inSuite, lEnd == lString + lLength);
NL_TEST_ASSERT(inSuite, errno == 0);

// 3: Test hexadecimal (16)
// 4: Test hexadecimal (16)

errno = 0;
lString = "0xaf";
Expand Down Expand Up @@ -608,6 +646,20 @@ static void TestShortLengths(nlTestSuite *inSuite __attribute__((unused)),
NL_TEST_ASSERT(inSuite, lResult == 12);
NL_TEST_ASSERT(inSuite, lEnd == lString + lLength);
NL_TEST_ASSERT(inSuite, errno == 0);

// 3: Test short implicit base with bare "0".
//
// "0x2A" with length 1 and implicit base should see only the '0',
// treat it as the value zero, and consume the one character.

errno = 0;
lString = "0x2A";
lLength = 1;

lResult = strntol(lString, lLength, &lEnd, 0); // or strntol for the signed suite
NL_TEST_ASSERT(inSuite, lResult == 0);
NL_TEST_ASSERT(inSuite, lEnd == lString + lLength);
NL_TEST_ASSERT(inSuite, errno == 0);
}

static void TestBadHexLeading(nlTestSuite *inSuite __attribute__((unused)),
Expand Down
58 changes: 55 additions & 3 deletions src/tests/Test_strntoul.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,45 @@ static void TestImplicitBase(nlTestSuite *inSuite __attribute__((unused)),
char * lEnd;


// 1: Test octal (8)
// 1: Test bare zero with implicit base

// 1.1: A bare "0" with implicit base should parse as the value
// zero (0), not be consumed as an octal prefix with no
// digits following.

errno = 0;
lString = "0";
lLength = strlen(lString);

lResult = strntoul(lString, lLength, &lEnd, kBase);
NL_TEST_ASSERT(inSuite, lResult == 0);
NL_TEST_ASSERT(inSuite, lEnd == lString + lLength);
NL_TEST_ASSERT(inSuite, errno == 0);

// 1.2: A bare "00" with implicit base should parse as zero (0)
// in octal and consume both characters.

errno = 0;
lString = "00";
lLength = strlen(lString);

lResult = strntoul(lString, lLength, &lEnd, kBase);
NL_TEST_ASSERT(inSuite, lResult == 0);
NL_TEST_ASSERT(inSuite, lEnd == lString + lLength);
NL_TEST_ASSERT(inSuite, errno == 0);

// 1.3: "01" with implicit base should parse as octal 1.

errno = 0;
lString = "01";
lLength = strlen(lString);

lResult = strntoul(lString, lLength, &lEnd, kBase);
NL_TEST_ASSERT(inSuite, lResult == 1);
NL_TEST_ASSERT(inSuite, lEnd == lString + lLength);
NL_TEST_ASSERT(inSuite, errno == 0);

// 2: Test octal (8)

errno = 0;
lString = "007";
Expand All @@ -156,7 +194,7 @@ static void TestImplicitBase(nlTestSuite *inSuite __attribute__((unused)),
NL_TEST_ASSERT(inSuite, lEnd == lString + lLength);
NL_TEST_ASSERT(inSuite, errno == 0);

// 2: Test decimal (10)
// 3: Test decimal (10)

errno = 0;
lString = "13";
Expand All @@ -176,7 +214,7 @@ static void TestImplicitBase(nlTestSuite *inSuite __attribute__((unused)),
NL_TEST_ASSERT(inSuite, lEnd == lString + lLength);
NL_TEST_ASSERT(inSuite, errno == 0);

// 3: Test hexadecimal (16)
// 4: Test hexadecimal (16)

errno = 0;
lString = "0xaf";
Expand Down Expand Up @@ -564,6 +602,20 @@ static void TestShortLengths(nlTestSuite *inSuite __attribute__((unused)),
NL_TEST_ASSERT(inSuite, lResult == 12);
NL_TEST_ASSERT(inSuite, lEnd == lString + lLength);
NL_TEST_ASSERT(inSuite, errno == 0);

// 3: Test short implicit base with bare "0".
//
// "0x2A" with length 1 and implicit base should see only the '0',
// treat it as the value zero, and consume the one character.

errno = 0;
lString = "0x2A";
lLength = 1;

lResult = strntoul(lString, lLength, &lEnd, 0); // or strntol for the signed suite
NL_TEST_ASSERT(inSuite, lResult == 0);
NL_TEST_ASSERT(inSuite, lEnd == lString + lLength);
NL_TEST_ASSERT(inSuite, errno == 0);
}

static void TestBadHexLeading(nlTestSuite *inSuite __attribute__((unused)),
Expand Down
108 changes: 73 additions & 35 deletions third_party/nlbuild-autotools/repo/third_party/autoconf/compile
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#! /bin/sh
# Wrapper for compilers which do not understand '-c -o'.

scriptversion=2012-01-04.17; # UTC
scriptversion=2018-03-07.03; # UTC

# Copyright (C) 1999, 2000, 2003, 2004, 2005, 2009, 2010, 2012 Free
# Software Foundation, Inc.
# Copyright (C) 1999-2018 Free Software Foundation, Inc.
# Written by Tom Tromey <tromey@cygnus.com>.
#
# This program is free software; you can redistribute it and/or modify
Expand All @@ -18,7 +17,7 @@ scriptversion=2012-01-04.17; # UTC
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# along with this program. If not, see <https://www.gnu.org/licenses/>.

# As a special exception to the GNU General Public License, if you
# distribute this file as part of a program that contains a
Expand Down Expand Up @@ -79,6 +78,53 @@ func_file_conv ()
esac
}

# func_cl_dashL linkdir
# Make cl look for libraries in LINKDIR
func_cl_dashL ()
{
func_file_conv "$1"
if test -z "$lib_path"; then
lib_path=$file
else
lib_path="$lib_path;$file"
fi
linker_opts="$linker_opts -LIBPATH:$file"
}

# func_cl_dashl library
# Do a library search-path lookup for cl
func_cl_dashl ()
{
lib=$1
found=no
save_IFS=$IFS
IFS=';'
for dir in $lib_path $LIB
do
IFS=$save_IFS
if $shared && test -f "$dir/$lib.dll.lib"; then
found=yes
lib=$dir/$lib.dll.lib
break
fi
if test -f "$dir/$lib.lib"; then
found=yes
lib=$dir/$lib.lib
break
fi
if test -f "$dir/lib$lib.a"; then
found=yes
lib=$dir/lib$lib.a
break
fi
done
IFS=$save_IFS

if test "$found" != yes; then
lib=$lib.lib
fi
}

# func_cl_wrapper cl arg...
# Adjust compile command to suit cl
func_cl_wrapper ()
Expand Down Expand Up @@ -109,43 +155,34 @@ func_cl_wrapper ()
;;
esac
;;
-I)
eat=1
func_file_conv "$2" mingw
set x "$@" -I"$file"
shift
;;
-I*)
func_file_conv "${1#-I}" mingw
set x "$@" -I"$file"
shift
;;
-l)
eat=1
func_cl_dashl "$2"
set x "$@" "$lib"
shift
;;
-l*)
lib=${1#-l}
found=no
save_IFS=$IFS
IFS=';'
for dir in $lib_path $LIB
do
IFS=$save_IFS
if $shared && test -f "$dir/$lib.dll.lib"; then
found=yes
set x "$@" "$dir/$lib.dll.lib"
break
fi
if test -f "$dir/$lib.lib"; then
found=yes
set x "$@" "$dir/$lib.lib"
break
fi
done
IFS=$save_IFS

test "$found" != yes && set x "$@" "$lib.lib"
func_cl_dashl "${1#-l}"
set x "$@" "$lib"
shift
;;
-L)
eat=1
func_cl_dashL "$2"
;;
-L*)
func_file_conv "${1#-L}"
if test -z "$lib_path"; then
lib_path=$file
else
lib_path="$lib_path;$file"
fi
linker_opts="$linker_opts -LIBPATH:$file"
func_cl_dashL "${1#-L}"
;;
-static)
shared=false
Expand Down Expand Up @@ -218,7 +255,8 @@ EOF
echo "compile $scriptversion"
exit $?
;;
cl | *[/\\]cl | cl.exe | *[/\\]cl.exe )
cl | *[/\\]cl | cl.exe | *[/\\]cl.exe | \
icl | *[/\\]icl | icl.exe | *[/\\]icl.exe )
func_cl_wrapper "$@" # Doesn't return...
;;
esac
Expand Down Expand Up @@ -302,9 +340,9 @@ exit $ret
# Local Variables:
# mode: shell-script
# sh-indentation: 2
# eval: (add-hook 'write-file-hooks 'time-stamp)
# eval: (add-hook 'before-save-hook 'time-stamp)
# time-stamp-start: "scriptversion="
# time-stamp-format: "%:y-%02m-%02d.%02H"
# time-stamp-time-zone: "UTC"
# time-stamp-time-zone: "UTC0"
# time-stamp-end: "; # UTC"
# End:
Loading