Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / StrCat Inserting Random Characters Into My Strings???

Author
Message
kklouzal
15
Years of Service
User Offline
Joined: 15th May 2009
Location: Arizona
Posted: 9th Jun 2009 08:55 Edited at: 10th Jun 2009 01:04
I have a client program that accepts 2 inputs from a player, username & password then sends them off to the server using DarkNet, The server recieves the username then strcat's it to another variable then that variable gets ".xml" strcatted (lol catted) onto the end of it and some irrelevant sutuff happens to it....

The issue here is that it seems strcat is sticking random characters into my new string either the first time it fires, last time, or both times. You can see how this would cause problems.

Here are a few different snippets of code showing everything during the process of taking in the variable all the way down to showing it on the 'console screen'

I've also included a picture of the random characters it sticks

**NOTE** this is most likely a server side issue since the random characters are ALWAYS the same ones *unless* I restart my server program, then its a different set of random characters. =[
It also seems as if this happens Most Of The Time, sometimes (hardly any) no random characters get strcatted and all goes well.

Getting text from the user & sending it to the server (class constructor):



Server side to recieve the message *DarkNet* (normal function)


ply.Login(...) (class constructor):


There you all go, that should be everything needed to solve this one =/ *believe me i've been trying for some days now*

When I tried to login as the client i put "test" into the username box & "1234" into the password box, which, is a valid account.

EDIT: forgot to add the image
EDIT: EDIT: uploaded the image to the post

Attachments

Login to view attachments
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 9th Jun 2009 18:11
This is the second time I've seen you use curtxt in a question. But in neither case do we see curtxt declared in your code. Is it a char* ? If so, does it point to a pre-existing character array or to space allocated with new? Or does it point to some random address in your memory space? If it's a char array was the array initialized to make sure it looked like a character string.

char curtxt [128] = ""; // guarantees that the array starts out null terminated

char *curtxt = new char [128];

Looking further at your code I notice that you may be replacing characters in a curtxt array with ' '. Since I don't know what numcount represents because it's not declared or initialized in your code fragment I can only guess. Are you making sure that your char array has a properly termination while you're manipulating it?

returns space for curtxt but the data isn't initialized. strcat is for concatenating strings. This means that it expects to find a destination string onto which another string will be appended. Both strings need to be properly constructed with null terminators. If curtxt is supposed to be empty at first it needs to begin with the null terminator. If curtxt is allocated as above you need to follow it with

*curtxt = '/0';

or

*curtxt = 0;

or

curtxt [0] = 0;

The latter line can be used whether curtext is a pointer to allocated space or a character array.

If

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
kklouzal
15
Years of Service
User Offline
Joined: 15th May 2009
Location: Arizona
Posted: 9th Jun 2009 23:16 Edited at: 9th Jun 2009 23:20
The part on the client side that im showing you is from a class,

like so:


class textbox {
char curtxt[255];
int XPos;
int YPos;
int Sprite;
int SpriteX;
int SpriteY;
int numcount;
bool selected;
bool bkpress;
public:
void Make ( int x, int y, int sprite, int spritex, int spritey );
void Do ( );
char *Value ( );
void Empty ( );
};


then:


void textbox::Make( int x, int y, int sprite, int spritex, int spritey )
{
selected = false;
bkpress = false;
XPos = x;
YPos = y;
Sprite = sprite;
SpriteX = spritex;
SpriteY = spritey;
numcount = 0;
}


And:


void textbox:o()
{
int mc = dbMouseClick();
int mx = dbMouseX();
int my = dbMouseY();
if (mc == 1)
{
if (mx > XPos+5 && mx < XPos+SpriteX-5 && my > YPos+6 && my < YPos+SpriteY-6)
{
selected = true;
} else {
selected = false;
}
}
if (selected == true)
{
dbText(0,0,dbStr(dbScanCode()));
if (dbKeyState(14) == 1)
{
if (numcount >= 0)
{
if (bkpress == false)
{
numcount--;
curtxt[numcount] = '';
bkpress = true;
}
}
}
if (dbKeyState(14) == 0)
{
bkpress = false;
de = dbGetEntry();
if (de != NULL)
{
if (strcmp(de, blank))
{
strcat ( curtxt, de );
numcount++;
dbText(10, 10, "running");
}
}
dbClearEntryBuffer ( );
}
}
dbPasteSprite ( Sprite, XPos, YPos );
dbText ( XPos+10, YPos+12, curtxt );
dbText ( XPos-100, YPos+12, dbStr(numcount) );
}


Then:


char *textbox::Value ( )
{
return(curtxt);
}


But thats not where the problem is here! The server recieves what is typed into my textboxes just fine, its when the server strcat's the variable then strcat's the ".xml" into it where problems rise..

EDIT: there are "code" things around my code i dont know why it didnt parse...

Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 9th Jun 2009 23:48
You don't have a constructor for textbox. At the very least I'd put one in that set curtxt [0] = 0.

I'm not following your code exactly since I'm not sure what your aim is but I see lots of opportunity for curtxt not to be properly null terminated.

If by

numcount--;
curtxt[numcount] = '';

you're trying to backfull a string to erase an existing trailing character you might be better off using 0 instead of ' '. But, again, I sort of guessing here.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
kklouzal
15
Years of Service
User Offline
Joined: 15th May 2009
Location: Arizona
Posted: 10th Jun 2009 00:03
alright, i've added curtxt[0] = '\0'; to my constructor and the random characters still get added server side..

Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 10th Jun 2009 00:07
Then I'm afraid I'm out of ideas. It would probably be hard to do but a debug session would seem to be in order.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
kklouzal
15
Years of Service
User Offline
Joined: 15th May 2009
Location: Arizona
Posted: 10th Jun 2009 00:10 Edited at: 10th Jun 2009 01:05
i will send you my entire project in a rar file source and all so you can see for yourself what's going on.. because im not sure you fully understand

EDIT: I just went through the entire project and commented it if you want it..

AlexI
19
Years of Service
User Offline
Joined: 31st Dec 2004
Location: UK
Posted: 10th Jun 2009 01:09
I cant be assed to look through your project but I think this may be the problem:

Problematic code:



Good code:



Alex

kklouzal
15
Years of Service
User Offline
Joined: 15th May 2009
Location: Arizona
Posted: 10th Jun 2009 01:34 Edited at: 10th Jun 2009 02:44
sigh, now if i try to run the server program outside of debugging in release mode(ex go to the folder where the exe is and run it) my client cant communicate with it... i click the login button and it just hangs no errors nothing on the servers console..i'll have to look into whats doing this now =/

EDIT: sorry, the client hangs when I type in a correct username, an incorrect username still sticks random characters

EDIT: EDIT: Some further investigation into this and i've fixed it!
All is working properly for now. ;]

kklouzal
15
Years of Service
User Offline
Joined: 15th May 2009
Location: Arizona
Posted: 10th Jun 2009 02:45
(Sorry for double post but they both need some kudos for the help)
Thanks Lilith & AlexI very very much i'd give you both $1000 if I had it xD

Login to post a reply

Server time is: 2024-10-01 03:23:11
Your offset time is: 2024-10-01 03:23:11