public inbox for libc-help@sourceware.org
 help / color / mirror / Atom feed
From: Allin Cottrell <cottrell@wfu.edu>
To: Michael Brunnbauer <brunni@netestate.de>
Cc: libc-help@sourceware.org
Subject: Re: my strstr is broken
Date: Tue, 11 Sep 2018 12:58:00 -0000	[thread overview]
Message-ID: <alpine.LNX.2.21.1809110851590.32470@robroy> (raw)
In-Reply-To: <20180911102711.GA31876@netestate.de>

[-- Attachment #1: Type: text/plain, Size: 2911 bytes --]

On Tue, 11 Sep 2018, Michael Brunnbauer wrote:

> hi all,
>
> I assume it cannot be reproduced and is limited to my build?
>
> Any ideas/hints for me? The fact that the needle is 513 bytes and occurs at
> an offset of 513 bytes in the haystack should provide some clue?
>
> cu,
> brunni
>
> On Mon, Sep 10, 2018 at 04:47:52PM +0200, Michael Brunnbauer wrote:
>>
>> can someone reproduce this with 2.28 (program exits with return code 255)?
>>
>> -----------------------------------------------------------
>> #include <string.h>
>>
>> int main (void)
>> {
>>  char* i = "                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
>>  char* n = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
>>  if (!strstr(i,n)) return 255;
>>  return 0;
>> }

Since it's difficult to verify your long strings in email I tried the 
following variant of your test:

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

int main (void)
{
     char h[513*2+1];
     char n[513+1];
     char *s;
     int i;

     for (i=0; i<513; i++) {
         n[i] = 'x';
         h[i] = ' ';
         h[i+513] = 'x';
     }
     n[513] = '\0';
     h[513*2] = '\0';

     printf("h=\"%s\"\n", h);
     printf("n=\"%s\"\n", n);
     s = strstr(h, n);
     printf("s = %p\n", (void *) s);
     printf("strcmp(n, s) = %d\n", strcmp(s, n));

     return 0;
}

Compiled with gcc 8.2.1 20180831 (Arch) the output is

s = 0x7ffe8771ae51
strcmp(n, s) = 0

--
Allin Cottrell
Department of Economics
Wake Forest University, NC

  reply	other threads:[~2018-09-11 12:58 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-10 14:47 Michael Brunnbauer
2018-09-11 10:27 ` Michael Brunnbauer
2018-09-11 12:58   ` Allin Cottrell [this message]
2018-09-11 13:54     ` Michael Brunnbauer
2018-09-11 14:21       ` Siddhesh Poyarekar
2018-09-11 14:41         ` Michael Brunnbauer
2018-09-11 14:51           ` Siddhesh Poyarekar
2018-09-11 15:21             ` Paul Pluzhnikov via libc-help
2018-09-11 15:38               ` Siddhesh Poyarekar
2018-09-11 18:46 Wilco Dijkstra

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=alpine.LNX.2.21.1809110851590.32470@robroy \
    --to=cottrell@wfu.edu \
    --cc=brunni@netestate.de \
    --cc=libc-help@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).