Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3368: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:472)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3370: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:472)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3371: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:472)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3372: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:472)
OrbWorks Community Forum • View topic - possible pointer assignment bug found

possible pointer assignment bug found

Discuss PocketC for CE (including Desktop Edition)

Postby Nik on Wed Sep 18, 2002 12:51 pm

Hi all,

i`ve found a possible pointer bug.
If a pointer is given as a argument to a function, the pointer will work inside the function properly (see console output). But outside the function, the whole array data has moved 2 fields (bad english, see console output) up (ae. outside array[2] is inside the ParseSpace function array[0]).

gettype says that the pointer type is "other" (o) and if gettype is used on seperate fields of the array (like gettype(array[1])), gettype reports for the first and second array entry that it is of type "other" all array entries after the second are strings.

if in main() the for loop begins at 0, the program crashes or doesn`t
execute any code anymore.

i`ve replaced the plus signs with the word "plus" in bold.

ParseSpaces(string Text, char ChrParseTo, int size, pointer pArray){
int i,ChrPos;
pArray=malloc(size);
settype(pArray,size,"s");
ChrPos=strchr(Text,ChrParseTo);
while (ChrPos!=-1){
pArray[i]=strmid(Text,0,strchr(Text,ChrParseTo));
putsl("inner function: "<b>plus</b>i<b>plus</b>" -- "<b>plus</b>pArray[i]);
Text=strmid(Text,strchr(Text,ChrParseTo)<b>plus</b>1,strlen(Text));
ChrPos=strchr(Text,ChrParseTo);
i<b>plus</b><b>plus</b>;
}
pArray[i]=strmid(Text,0,strlen(Text));
putsl("P. in function: "<b>plus</b>i<b>plus</b>" -- "<b>plus</b>pArray[i]);
return i;
}



main(){
int StackDimension,i,j,k;
char ChrToParse;
string TestText;
pointer aPointer;
j=ParseSpaces("#000 #111 #222 #333 #444 #555 #666 #777 #888 #999"," ",20,aPointer); // returns number of entries
alert(typeof(aPointer));
for (k=1;k<j<b>plus</b>5;k<b>plus</b><b>plus</b>){
putsl("outer function: "<b>plus</b>k<b>plus</b>" -- "<b>plus</b>aPointer[k]);
}
}


best regards, nik
Nik
 
Posts: 15
Joined: Tue Dec 04, 2001 7:33 am

Postby guy on Wed Sep 18, 2002 1:25 pm

You're passing a local copy of the pointer aPointer from main() into ParseSpaces(). Changes to pArray inside ParseSpaces won't have any effect on variable aPointer outside the function.

If you display the value of aPointer after the call to ParseSpaces you'll see that it still has the same value as before the call.

What you need to do is pass a pointer to a pointer so that you can get the value back:

ParseSpaces(..., pointer ppArray) {
pointer pArray ;
:
:
:
*ppArray = pArray ;
}

main() {
:
:
:
j=ParseSpaces(..., &aPointer) ;


Guy
[url]mailto:pcform@pcform.net[/url]
http://www.pcform.net
PocketC CE API interface: http://www.networkdynamics.net/PCForm.html#library
PCForm and CE API forum: http://www.networkdynamics.net/forum
Guy
[url]mailto:pcform@pcform.net[/url]
http://www.pcform.net
PocketC CE API interface: http://www.networkdynamics.net/PCForm.html#library
PCForm and CE API forum: http://www.networkdynamics.net/forum
guy
 
Posts: 879
Joined: Thu Dec 07, 2000 8:58 am
Location: United Kingdom

Postby Nik on Thu Sep 19, 2002 10:40 am

Thx for support Guy, now everything works fine

but i have also a little question ;)

>You're passing a local copy of the pointer aPointer from main() into
>ParseSpaces(). Changes to pArray inside ParseSpaces won't have any
>effect on variable aPointer outside the function.

Is it just luck with the PocketC memory management that the program doesnt crash and that the pointer aPointer does show the values (shifted 2 fields, starts at 2) whose should have been gone ?

aPointer[0], Ptype="o" ,value=? (app crashes or stops)
aPointer[1], Ptype="o" ,value=0
aPointer[n+2],Ptype="s" ,value=pArray[n]


Nik
Nik
 
Posts: 15
Joined: Tue Dec 04, 2001 7:33 am

Postby guy on Thu Sep 19, 2002 1:58 pm

> Is it just luck with the PocketC memory management that the
> program doesnt crash and that the pointer aPointer does show the
> values (shifted 2 fields, starts at 2) whose should have been gone ?

It's not luck. It just happens to be what you have coded, combined with the values that PocketC returns from malloc.

The pointer starts off with value 0 in main, because you haven't assigned anything to it.

When you call malloc() in ParseSpaces() the return value that you're getting is probably 2 (0 is a null pointer and 1 is likely to be the "address" of the ParseSpaces() function in your program - hence type "o"). 0 may even be a pointer to function main() rather than the null pointer.

So then when you reference entries outside ParseSpaces() then 0 is a reserved address, 1 is a function address, 2 is the first address in allocated memory. Hence the apparent movement by two positions.

Actually referencing memory addressed by a function pointer in PocketC shouldn't really crash the program, but the value isn't meaningful.



Guy
[url]mailto:pcform@pcform.net[/url]
http://www.pcform.net
PocketC CE API interface: http://www.networkdynamics.net/PCForm.html#library
PCForm and CE API forum: http://www.networkdynamics.net/forum
Guy
[url]mailto:pcform@pcform.net[/url]
http://www.pcform.net
PocketC CE API interface: http://www.networkdynamics.net/PCForm.html#library
PCForm and CE API forum: http://www.networkdynamics.net/forum
guy
 
Posts: 879
Joined: Thu Dec 07, 2000 8:58 am
Location: United Kingdom


Return to PocketC for CE

Who is online

Users browsing this forum: No registered users and 3 guests

cron