WAD bpokestr issue

May 20, 2008
473
2
In this example, I try to allocate a binary buffer of size 10 and write a repeated value into it. A smaller length value works, but not a value of length the same size as the binary buffer.
Code:
C:\tmp>ver

TCC  23.00.17 x64   Windows 10 [Version 10.0.17134.112]

C:\tmp>set b=%@balloc[10]

C:\tmp>echo %@bpokestr[%b,0,a,%@repeat[x,10]]
TCC: (Sys) The parameter is incorrect.
 "%@bpokestr[000001DCECC12080,0,a,xxxxxxxxxx]"

C:\tmp>set value=%@repeat[x,10]

C:\tmp>echo %@bpokestr[%b,0,a,%value]
TCC: (Sys) The parameter is incorrect.
 "%@bpokestr[000001DCECC12080,0,a,xxxxxxxxxx]"

C:\tmp>echo %@len[%value]
10

C:\tmp>echo %@bpokestr[%b,0,a,12345]
0

C:\tmp>echo %@bpokestr[%b,0,a,1234567890]
TCC: (Sys) The parameter is incorrect.
 "%@bpokestr[000001DCECC12080,0,a,1234567890]"
 
May 20, 2008
11,401
99
Syracuse, NY, USA
10 characters is too many for a 10-byte (string) buffer. Internally the string will be terminated by a NUL character.
 
May 20, 2008
473
2
I know about the need to allocate for the terminating NULL char in C/C++. Been handling that for decades. But, if that is a limit in the TCC language, it's not documented in an obvious way. The example for @bpokestr uses a buffer of 128, though writing a shorter string. Maybe I missed it, but I didn't see anything in the function docs about needing to allocate more or write the string to the buffer in blocks. If I allocate @balloc[%@inc[%size]], then the %size string will write fine. I cannot guess at intentions and can only go by the documentation.
 
May 20, 2008
11,401
99
Syracuse, NY, USA
You're right. A note in @BPOKESTR's help is in order, perhaps something as simple as

Note that strings are automatically terminated by a NUL character. So an n-character string will require an n+1-character buffer. That's 1 extra byte for an ASCII string, 2 extra bytes for a Unicode string.
 
May 20, 2008
473
2
Then, we get into the related issues of needing to NOT fill that position in a string, of writing the trailing NULL, possibly not when reading, or when using that binary buffer such as for unqlite. But, I'm not sure if these requirements are intended to force someone using TCC to think like a C/C++ developer.
 
Similar threads
Thread starter Title Forum Replies Date
H @BPokeStr vs. @BRead Support 2
cgunhouse TCToolBar /W Issue Support 1
G v28 Display Issue Support 7
Jay Sage Issue with CD_ENTER Alias Support 37
Jay Sage Issue with CD_LEAVE Alias Support 3
fpefpe How to? issue with % and evaluation Support 5
cgunhouse Standard User Account Issue Support 2
samintz WAD Display wrapping issue Support 5
M TCC color issue in ConEmu Support 4
samintz Timer issue Support 4
Alpengreis Documentation Minor issue in help file for view /E Support 1
samintz WAD ANSI issue Support 3
D TCSTART issue after reinstallation Support 14
A Documentation [Help file] OPTION "//" synopsis formatting issue Support 0
Chen Touboul Overtyping issue - i press the Insert key, help till press enter for new line in TCC Support 2
Y TCC and Cmder imcompatibility issue Support 7
M Another possibly strange remote registry issue Support 5
D High-DPI Scaling issue Support 1
S CMDebug 22 issue with del command Support 1
cgunhouse Foldermonitor Issue Support 7
samintz Build 38 Install issue Support 5
rps WAD Setlocal issue Support 4
Luiz Rodrigues Issue with Maven Support 1
Seven Update / install issue with 20.0.20.10.32 take command Support 7
Fross WebDav Drive Mapping Issue Support 19
D Upgrade issue Support 3
Fross V20b8 Everything Issue Support 5
T TCC display issue Support 1
cgunhouse _logfile Issue Support 5
T Fixed Querybox issue Support 1
cgunhouse Fixed Share Memory Issue Support 5
cgunhouse Foldermonitor with "/E" Option Issue Support 6
Fross TabComplete Argument Issue Support 1
fpefpe How to? Stange start up issue Support 1
C cosmetic issue with LIST's (I) Support 9
jbarnes1967 TC 18.00 x64 issue with lua io.popen() Support 2
D How to? Wildcards as sets - looping issue with FOR and REN Support 7
T WAD Free issue Support 6
R Fixed v17.0.54 Tab->COMSPEC Dialog Box Issue Support 2
R Minor Cosmetic Issue in Take Command Window Support 2
cgunhouse One line IFF ... Then ... Else ... EndIFF Statement issue in V17 Support 13
cgunhouse IFTP Path Issue in V17 - Fixed Support 7
S BDEBUGGER issue Support 9
cgunhouse @ISPROC Issue Support 15
cgunhouse TCMD.INI Issue Support 7
T Fixed multi-line alias issue Support 13
R WAD issue with filename completion with system and hidden files Support 8
D Strange issue with FOR loop Support 15
C Install Issue with 3rd Party Privelege Escalation Support 2
W Button command issue Support 5

Similar threads