public inbox for newlib@sourceware.org
 help / color / mirror / Atom feed
From: "Allen, Richard" <Richard.Allen@garmin.com>
To: "newlib@sourceware.org" <newlib@sourceware.org>
Subject: strsep final separator handling
Date: Tue, 8 Sep 2020 15:51:27 +0000	[thread overview]
Message-ID: <7e6c437cb3af4974a42f04f774880d60@garmin.com> (raw)

Hello,

I think I have identified a small difference between newlib strsep
and GNU/BSD strsep's handling of separators at the end of a string.

GNU and BSD strsep will return a pointer to the null terminating
character when asked to process a separator ending immediately before
a null-termination character. newlib strsep seems to return NULL instead.

Similarly, when presented with an empty string, GNU and BSD strsep will
return a pointer to the null terminating character, but newlib strsep
will return NULL.

I found this on _NEWLIB_VERSION "2.2.0" built for ARMv7-AR, but
I do not believe the implementation has changed since then when 
comparing to the master branch in git.

Here is a short example program that prints Found: three times 
when using GNU/BSD strsep, but only twice using newlib strsep:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define TEST_STRING ",,"
#define DELIM ","

int main()
{
char * str = strdup(TEST_STRING);
char * found;
char * strwalker = str;

while( (found = strsep(&strwalker,DELIM)) != NULL )
    {
    printf("Found:%s\n",found);
    }

free(str);
}

-Richard

                 reply	other threads:[~2020-09-08 15:51 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7e6c437cb3af4974a42f04f774880d60@garmin.com \
    --to=richard.allen@garmin.com \
    --cc=newlib@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).