Truncated GL_EXTENSIONS String

This is a strange one…

I’m attempting to read the extension string in with:

char *pString;
pString = (char *)glGetString(GL_EXTENSIONS);

This has worked flawlessly in the past, now it gets a string that’s truncated at about 240 characters, with no \0 on the end to terminate the string.

I’m using the latest OpenGL 1.4, included in the NVidia 40.41 drivers.

Any ideas?

Strange…

Have you tried doing a strncpy into a buffer?

char ext[2048];
strncpy( buf, (const char*)glGetString(GL_EXTENSIONS),sizeof(ext)-1);

Originally posted by fresh:
[b]Strange…

Have you tried doing a strncpy into a buffer?

char ext[2048];
strncpy( ext, (const char*)glGetString(GL_EXTENSIONS),sizeof(ext)-1);

[/b]

This has worked flawlessly in the past, now it gets a string that’s truncated at about 240 characters, with no \0 on the end to terminate the string.

Maybe I’m missing something here, but how is it “truncated” if there’s no ‘\0’ at the end? Is there just random nonsense after 240 characters?

Originally posted by fresh:
[b]Strange…

Have you tried doing a strncpy into a buffer?

char ext[2048];
strncpy( buf, (const char*)glGetString(GL_EXTENSIONS),sizeof(ext)-1);

[/b]

I wouldn’t recommend doing that. The buffer may be too small, or you might read far beyond the end of the end of the string and cause a crash.

Well, turns out it works fine. Thanks for the tips, though… you guys got me thinking “outside the box”. I took another look and realized that the problem had to be in my code. Sure enough…

FYI:
sizeof(ext)-1 = sizeof(char *)-1 = 3 (on a 32-bit system), when ext is declared as:
char ext[2048];

sizeof(ext) returns 2048. It’s an array, not a pointer. Arrays and pointer have lots of similarities, but this is a time where there is a clear difference.

You’re absolutely right! Sorry.