Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 07 Oct 2004
Offline Last Active Today, 02:19 AM

Posts I've Made

In Topic: Weird if() behavior

18 October 2014 - 01:33 PM

for(int i = 1; i < 10; i++)
backlog[i] = backlog[i-1];


fyi, i think this is wrong.. everything will be set to backlog[0]. I think you need to do the loop in reverse.

In Topic: Win32 API, GetMessage() after PeekMessage()

20 July 2014 - 08:01 PM

afaik, PM_NOREMOVE causes the PeekMessage() to leave the message on the queue. GetMessage() then removes the message from the queue.


edit: although this example would probably be fine with just the PeekMessage() without the PM_NOREMOVE.

In Topic: File Loading Adds Weird Characters to the end

19 May 2014 - 05:00 PM

 As far as i know, a text file is treated similar to binary file except that some os's do some linefeed, carriage return translations. Text files are sometimes parsed by reading line-by-line, which, in c++, is straightforward to do (std::getline()). You have the filesize, you know when you've reached the end of file, and you can read line-by-line if you want. Thinking from a text file point of view, i don't even think '\0' is valid in it (does getline() stop at the '\0'). I guess what i'm trying to say, a text file is basically a binary file except it generally contains printable text rather than some sort of binary data and a '\0' would be considered binary data.


 (did i get that right, lol) 


EDIT: ninja'd

In Topic: File Loading Adds Weird Characters to the end

19 May 2014 - 04:17 PM

 You need to add a '\0' c-string terminator. make the char buffer 1 bigger, then when you read it, assign the last char in the array a value of 0. 


int filesize = whatever;
char *buf = new char[filesize + 1];
buf[filesize] = 0;


 This is needed as a c-string holds a null terminator to signify the end of the string.

In Topic: Strange "read" and "write" functions in OIS

19 May 2014 - 01:45 PM


The code in question is here:

//We are in non blocking mode - we just read once, and try to fill up buffer
input_event js[JOY_BUFFERSIZE];
int ret = read(mJoyStick, &js, sizeof(struct input_event) * JOY_BUFFERSIZE);
if( ret < 0 )

It may just be me, but that looks like a buffer overflow.


Don't think so. read reads bytes and the array size is specified correctly.