Skip to content
Low-level programming · Higher-level thinking
Login Register
Forum / Bugs and Fixes

possible bug with strCopyLen

A community discussion post from the original code:zIRON forum.

Molotov member
Posts
49
Threads
21
Location
Behind Keyboard

possible bug with strCopyLen

when is was printing the information copied i keept getting some jibberish, like it was reading past the mem used for that string. so i made this to test and as i suspected, seems like strcopylen doesn´t add 0 at the end of the buffer

program WIN32CUI 'Test';

#include 'ch.zir';
#include 'fileio.zir';
#include 'strings.zir';

char curVar[25], server_name[25];

strCopyLen(@curVar, 'testing a thing here', 20);
strCopyLen(@curVar, 'name', 4);


strLen(@curVar);
strCopyLen(@server_name,@curVar, eax);
print('curVar= ',@curVar, '\r\n');

wait_key(nil);

ExitProcess(0);

prints

curVar= namening a thing here

"Lerning new things is what life is all about, if you are always doing the same old things day in and day out you might aswell just kill yourself." - ME d^_^b

Replies

Colin admin
Posts
928
Threads
49
Location
Bulgaria
strCopyLen(@curVar, 'testing a thing here', 21);
strCopyLen(@curVar, 'name', 5);

this will output

curvar = name;

Colin admin
Posts
928
Threads
49
Location
Bulgaria

just to note that 'const strings' have an auto null byte, so if you want to append that too you need to add the extra 1 char size.

a sample scenario:

var1 = 'testing';

strCopyLen(@var1, 'post', 4);

var1 will now equal "posting"

but....

strCopyLen(@var1, 'post', 5);

var1 will equal "post"

hope this helps.

Molotov member
Posts
49
Threads
21
Location
Behind Keyboard

ah thanks.. =)

"Lerning new things is what life is all about, if you are always doing the same old things day in and day out you might aswell just kill yourself." - ME d^_^b