Strange problem with newlib strstr function and rtems 4.10 on coldfire

Paul Whitfield paulw at
Mon Apr 18 02:51:29 UTC 2011

Hello All,

I have a weird problem with the strstr function seeming to not work 
correctly on Rtems 4.10 with a Coldfire processor.

The problem is that strstr appears to be matching on where there is no

I have a code snippet below that shows the problem.

I expect that the "result" below would be a string pointing
to the first occurrence of "<%" in the string, i.e.
pointing to "<% company_name() ...
However what I am getting is a pointer to <html>

This is causing web pages service by the httpd web-server
to not work correctly (previously this worked fine
with RTEMS4.6).

If I swap the strstr with the mystrstr() function shown below
it works correctly.

Is this a newlib bug?


char *needle = "<%";
char *haystack = "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 
             "<meta http-equiv=\"Window-target\" content=\"_top\">\n"
             "<title><% company_name(); %>  <% firmware_name(); %></title>"
             "<script type=\"text/javascript\">";

  char *result ;

  result = strstr(haystack,needle);

  printf("Result is %s\n", result);


/* Implementation of strstr cribbed from the internet */
char * mystrstr(const char * in , const char * str )
     char c;
     size_t len;

     c = *str++;
     if (!c)
         return (char *) in;	// Trivial empty string case

     len = strlen(str);
     do {
         char sc;

         do {
             sc = *in++;
             if (!sc)
                 return (char *) 0;
         } while (sc != c);
     } while (strncmp(in, str, len) != 0);

     return (char *) (in - 1);


Paul Whitfield
Software Engineer

27 Sarich Court, Osborne Park
Perth WA 6017
P:  +61 8 9445 2633
F:  +61 8 9445 1687
I: <>

  Please consider the environment before printing this email.
This message and any attachment are confidential. If you are not the
intended recipient, please telephone or email the sender and delete the
message and any attachment from your system. If you are not the intended
recipient you must not copy this message or attachment or disclose the
contents to any other person.

Message  protected by MailGuard: e-mail anti-virus, anti-spam and content filtering.

More information about the users mailing list