bugs in strlen, strstr setlocale -- i386

Nikola Vladov <[email protected]>
Newsgroups gmane.linux.lib.dietlibc
Message-ID <[email protected]>
I wried to build wget static.  The result is segmantation fault 
on i386.

I found the folowing problems:

#include <string.h>
int main() {
  return strlen((char *)0);
}

This gives segmentation fault!  
As a result strstr(0, "UTF-8") works also wrong.

The key is function setlocale.  I changed it so and then all
works fine.  

#include <locale.h>
#include <stdlib.h>
#include <string.h>
#include "dietlocale.h"

char *setlocale (int category, const char *locale) {
  lc_ctype=CT_8BIT;
  if (locale) {
    if ((category==LC_ALL || category==LC_CTYPE)) {
      if (!*locale) {
	const char* x;
	x=getenv("LC_CTYPE");
	if (!x) x=getenv("LC_ALL");
	if (!x) x="C";
	locale=x;
      }
    }
    if (strstr(locale,".UTF-8") || strstr(locale,".UTF8")) lc_ctype=CT_UTF8;
    if ((locale[0]!='C' || locale[1])) return 0;
  }
  return "C";
}


In wget source exist the line
oldlocale = setlocale (LC_TIME, NULL);
and it makes problems.  

Nikola
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.