PDA

View Full Version : Truncated GL_EXTENSIONS String



xenovore
09-19-2002, 12:28 PM
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?

fresh
09-19-2002, 12:41 PM
Strange..

Have you tried doing a strncpy into a buffer?

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

fresh
09-19-2002, 12:45 PM
Originally posted by fresh:
Strange..

Have you tried doing a strncpy into a buffer?

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

*Aaron*
09-19-2002, 01:42 PM
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?

Humus
09-19-2002, 03:51 PM
Originally posted by fresh:
Strange..

Have you tried doing a strncpy into a buffer?

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



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.

xenovore
09-19-2002, 05:45 PM
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... http://www.opengl.org/discussion_boards/ubb/smile.gif

*Aaron*
09-20-2002, 05:19 AM
FYI:
sizeof(ext)-1 = sizeof(char *)-1 = 3 (on a 32-bit system), when ext is declared as:
char ext[2048];

Humus
09-20-2002, 05:55 AM
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.

*Aaron*
09-20-2002, 08:39 AM
You're absolutely right! Sorry.