Pages: [1]   Go Down
Author Topic: String Overflow  (Read 999 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Sr. Member
****
Karma: 1
Posts: 415
MEGA_Stick_II is here
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This really isn't an Arduino question, but there are some really good programers here so thought I would ask,

This code snipit produces a Temp$ over flow
Code:
      string Temp$[150];

do
{
iNextChr = GetC(CopyBuf$);
if(iNextChr <> 0x2C && iNextChr <> 0x2E && iNextChr <> 0x3B) //Filter out the . , and ;
{
Temp$ = Temp$ + Chr(iNextChr);
//Print("%s",Temp$);
}
else if(iNextChr = 0x2C || iNextChr = 0x3B)
{
iData[iD] = AtoI(Temp$);
iD = iD + 1;
Temp$ = "";
}
}
until (iNextChr = 0x3B);

        Temp$ = "";


But changing it to this does not produce a Temp$ overflow and I'm not sure why. I might be misunderstanding how the Do Until loop works.

Code:
string Temp$[150];

        while(Len(CopyBuf$) > 0)
{
iNextChr = GetC(CopyBuf$);

if(iNextChr <> 0x2C && iNextChr <> 0x2E && iNextChr <> 0x3B) //Filter out the . , and ;
{
Temp$ = Temp$ + Chr(iNextChr);
//Print("%s",Temp$);
}
else if(iNextChr = 0x2C || iNextChr = 0x3B)
{
iData[iD] = AtoI(Temp$);
iD = iD + 1;
Temp$ = "";
}
}

Temp$ = "";

Thanks
« Last Edit: March 04, 2013, 10:58:34 pm by Jassper » Logged

0
Offline Offline
Shannon Member
****
Karma: 159
Posts: 10409
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Its not C!, some flavour of Basic?
Logged

[ I won't respond to messages, use the forum please ]

0
Offline Offline
Sr. Member
****
Karma: 1
Posts: 415
MEGA_Stick_II is here
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
until (iNextChr = 0x3B);
What purpose is served by assigning a value to iNextChr in this statement? It looks like an equality test would be more appropriate.

Sorry, should have mentioned that this is Crestron Simpl+ programing (Their own version of C) so unlike most where it would normally be == it is only =, so it is in fact an equality test. Using == doesn't compile.

Logged

UK
Offline Offline
Shannon Member
****
Karma: 183
Posts: 11138
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Your termination conditions are different.

The second implementation would process each received character and then stop.

The first implementation would continue reading characters until it finds a 0x3B. If there is no 0x3B in the input stream, and the GetC() function doesn't return 0x3B when there is no more input, then the first implementation will loop forever appending whatever GetC() returns to the string.
Logged

I only provide help via the forum - please do not contact me for private consultancy.

0
Offline Offline
Sr. Member
****
Karma: 1
Posts: 415
MEGA_Stick_II is here
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Your termination conditions are different.

The second implementation would process each received character and then stop.

The first implementation would continue reading characters until it finds a 0x3B. If there is no 0x3B in the input stream, and the GetC() function doesn't return 0x3B when there is no more input, then the first implementation will loop forever appending whatever GetC() returns to the string.

I kind of thought that myself but the 0x3B is the terminating character for each incoming string, so it should stop at the end. Not to mention that after each comma, the Temp$ should be = ""
Logged

0
Offline Offline
Sr. Member
****
Karma: 1
Posts: 415
MEGA_Stick_II is here
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

More info,

Example of incoming string, (random numbers)

100,34.2,50,65.0,600,0.0,0,40.0,200,34.0,24,50.0,100,35.0,20,40.0,0,0,0,0,25,95;

If I un-comment the print statement to see what Temp$ is I get

10034250650600000400200340245001003502040000002595

on the very first loop and each loop after

Furthermore the information stored in iData[] is correct
iData[0] = 100
iData[1] = 342
iData[2] = 50
iData[3] = 650
etc...

It's working now using the while loop but I am just trying to understand why it isn't working in the do-until loop.
 smiley-eek


Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Sorry, should have mentioned that this is Crestron Simpl+ programing

Yes you should definitely have mentioned that. There probably aren't that many Crestron Simpl+ experts on an Arduino/C++ forum.

Isn't there a Crestron Simpl+ forum? This seems totally out of place to me.

Next you'll want help fixing your car.
Logged

0
Offline Offline
Sr. Member
****
Karma: 1
Posts: 415
MEGA_Stick_II is here
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote from: Nick Gammon

Next you'll want help fixing
your car.

Yes and no. They think their product is gold so you don't get a straight answers or they expect to get
paid for every bit of info.

Like I said, there are a lot of
good programmers here.
But i see there a few dick's   as well.
Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 176
Posts: 12285
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Like I said, there are a lot of good programmers here.  But i see there a few dick's as well.

From one sarcastic remark you conclude that Nick is a bad programmer and a "few dick's"?

I can't tell if that is or is not an insult.  It could be.  But you incorrectly tried to make "dick" plural when referring to a single person.  As written it is statement of what is before your eyes rather than an insult.  From his published work, Nick is clearly a decent programmer which directly contradicts your implied mutual exclusion.  Your statement makes no sense.  You should rewrite it.

Maybe your post was meant to be sarcastic.  Is that the case?  Was your post an attempt at sarcasm?
Logged

0
Offline Offline
Sr. Member
****
Karma: 1
Posts: 415
MEGA_Stick_II is here
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Like I said, there are a lot of good programmers here.  But i see there a few dick's as well.

From one sarcastic remark you conclude that Nick is a bad programmer and a "few dick's"?

I didn't say he was a bad programmer smiley-wink

If you have nothing to offer to the problem, then just don't replay. He didn't need to belittle, and your post is no better by trying to show your superiority by correcting my grammar and insinuations. Nicks reply was uncalled for just as mine was unfounded. Nick concluded from one post that I'm an Idiot so yes, I concluded from one sarcastic remark that Nick is a dick - seems fair.

The programing is C++ based, the basics are the same. My hope was that someone would have a "possible" reason. I wasn't asking someone to re-write the code in proper syntax - obviously that's not going to happen. PeterH and PaulS at least both offered something constructive and I think PeterH has come close. It at least confirmed that I was on the write track.

That's why I come here, because I get helpful information - regardless.

Now, I have this funny noise in my car....


Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I never said you are an idiot. I doubt if you are. smiley

I looked at your code for a while, trying to be helpful, but got stuck on this line:

Code:
until (iNextChr = 0x3B);

In C++ that would be almost certainly wrong, as that is assigning, not comparing. However clearly the code wasn't C (or C++) and you hadn't specified what it is. Although I know quite a few languages that didn't match any I was familiar with. PHP it looked a bit like, however the AtoI was the wrong case for PHP. You see, I tried to do a bit of research for you.

Hence my frustration at being asked to help with so little effort being put into specifying the language. You said it "isn't an Arduino question". It would have been helpful to say "this is a Crestron Simpl+ question".

You go on to say:

Quote
The programing is C++ based, the basics are the same.

and also:

Quote
this is Crestron Simpl+ programing (Their own version of C) so unlike most where it would normally be == it is only =, so it is in fact an equality test. Using == doesn't compile.

So it's C++ based, but not.
Logged

California
Offline Offline
Faraday Member
**
Karma: 82
Posts: 3123
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I didn't say he was a bad programmer smiley-wink
...
Nick concluded from one post that I'm an Idiot

... And he didn't say you were an idiot.
Logged

Pages: [1]   Go Up
Jump to: