You are not logged in.

#1 2014-07-16 12:24:17

probablymyfault
Member
Registered: 2014-07-16
Posts: 2

possible issue with glibc or gcc?

Hi

I'm having an issue when running the following program:

#include <wchar.h>
int main() {
  mbstate_t mbs;
  mbrlen (NULL,0,&mbs);
}

After compiling with gcc, the program aborts from an assertion internally inside the glibc function __mbrtowc

./a.out 
a.out: mbrtowc.c:103: __mbrtowc: Assertion `((data.__statep)->__count == 0)' failed.
Aborted

The assertion seems testing if the struct mbstate_t object has been set to the initial state after a call to gconv.

The program works fine if compiled with clang.

Here is some system information:

~ pacman -Q glibc gcc
glibc 2.19-5
gcc 4.9.0-5

~ locale -a
C
en_CA.utf8
POSIX

~ locale
LANG=en_CA.UTF-8
LC_CTYPE="en_CA.UTF-8"
LC_NUMERIC="en_CA.UTF-8"
LC_TIME="en_CA.UTF-8"
LC_COLLATE="en_CA.UTF-8"
LC_MONETARY="en_CA.UTF-8"
LC_MESSAGES="en_CA.UTF-8"
LC_PAPER="en_CA.UTF-8"
LC_NAME="en_CA.UTF-8"
LC_ADDRESS="en_CA.UTF-8"
LC_TELEPHONE="en_CA.UTF-8"
LC_MEASUREMENT="en_CA.UTF-8"
LC_IDENTIFICATION="en_CA.UTF-8"
LC_ALL=

Testing the same program with LC_ALL="C" and LC_ALL="POSIX" both produce the same error.

I tested this program on a friend's RedHat installation, and it worked fine (I can collect more system information later if relevant).

From here I don't know where to look / who to ask.  Any advice would be greatly appreciated.

Offline

#2 2014-07-16 12:46:01

falconindy
Developer
From: New York, USA
Registered: 2009-10-22
Posts: 4,111
Website

Re: possible issue with glibc or gcc?

In what real case are you passing a NULL pointer to mbrlen? What do you expect this to do?

Last edited by falconindy (2014-07-16 12:46:08)

Offline

#3 2014-07-16 13:11:57

probablymyfault
Member
Registered: 2014-07-16
Posts: 2

Re: possible issue with glibc or gcc?

Hi
I was expecting it to initialize the mbstate_t struct as seen in this example.

A slightly different example which uses mbrtowc and has the same problem is:

#include <wchar.h>
int main() {
  mbstate_t mbs;
  mbrtowc(NULL, "", 1, &mbs);
}

Offline

#4 2014-07-17 22:27:37

falconindy
Developer
From: New York, USA
Registered: 2009-10-22
Posts: 4,111
Website

Re: possible issue with glibc or gcc?

Then file a bug with glibc folks. The documentation you cite on cplusplus.com is misleading, if not incorrect.

Offline

#5 2014-07-17 23:55:57

progandy
Member
Registered: 2012-05-17
Posts: 5,203

Re: possible issue with glibc or gcc?

The c standards do not define the result of calling mbrlen or mbrtowc with an uninitialized state. Maybe clang defaults to setting new structures to zero, while gcc does not. This works:
Edit: The problem may very well be inside the gconv modules, the mbr functions look fine to me.

#include <wchar.h>
#include <string.h>

int main() {
  mbstate_t mbs;
  memset(&mbs, 0, sizeof(mbs)); // initialize 

  mbrlen (NULL,0,&mbs);
}

Last edited by progandy (2014-07-18 00:04:31)


| alias CUTF='LANG=en_XX.UTF-8@POSIX ' |

Offline

Board footer

Powered by FluxBB