Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #36045
| Newsgroups | comp.lang.forth |
|---|---|
| Date | 2015-01-26 11:21 -0800 |
| References | <174b22de-2454-4e17-ac18-6a1333ec408f@googlegroups.com> <op.xsx0jbi0v6dtjm@localhost> |
| Message-ID | <d55e2379-92cb-454c-bb04-059c86ab8eb6@googlegroups.com> (permalink) |
| Subject | Re: Counted string |
| From | Marek Brunda <marekb@phoenics.org> |
Dne sobota 24. ledna 2015 2:17:25 UTC+1 Rod Pemberton napsal(a): > On Mon, 19 Jan 2015 02:54:49 -0500, Marek Brunda <marekb@phoenics.org> > wrote: > > > Hi, can anyone explain me, what's wrong with counted strings? Maybe it's > > a stupid question, but I've never understood it. Thanks > > This has been discussed many times here in the past. > You can search the Google Groups archive of this Usenet group. > > Nul-terminated strings replaced counted strings for the most part > many decades ago in most programming languages, e.g., 1970's or 1980's. > > The problem back then with counted strings was that the count could > be changed, but the length of the string wouldn't be. I.e., there > is a mismatch in the size of the count and the actual length of the > string. If the count is too short, then the string is truncated. > This isn't a problem. If the count is too large, then you have a > very serious issue. More space for a new larger string wasn't > allocated. The string is the same size, but the count is larger. > So, the oversized count value allows you to access data PAST the > actual end-of-string. I.e., you can read data you shouldn't have > access to, or write to variables you shouldn't have access to. > This is the same technique used by hackers for buffer overflow. > > (FYI, to prevent flame war, there are those here who claim that > can't actually happen in Forth ...) > > Languages like C which use nul-terminated strings frequently > only need to detect the end-of-string. They generally don't > need to know the string's length. So, not counting the length > of a string and just appending a nul-terminator to create a > string increased code speed. Of course, not terminating > a string in C, which happens with some string functions under > certain conditions, can cause overruns or unintended access too. > > > Rod Pemberton I read all the posts and I understand the arguments. So why not use NULL terminated strings in Forth?
Back to comp.lang.forth | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Counted string Marek Brunda <marekb@phoenics.org> - 2015-01-18 23:54 -0800
Re: Counted string "Elizabeth D. Rather" <erather@forth.com> - 2015-01-18 22:08 -1000
Re: Counted string anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-01-19 09:36 +0000
Re: Counted string "HAA" <someone@microsoft.com> - 2015-01-20 00:21 +1100
Re: Counted string Coos Haak <chforth@hccnet.nl> - 2015-01-19 14:44 +0100
Re: Counted string Raimond Dragomir <raimond.dragomir@gmail.com> - 2015-01-20 00:45 -0800
Re: Counted string anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-01-20 13:12 +0000
Re: Counted string Raimond Dragomir <raimond.dragomir@gmail.com> - 2015-01-21 01:05 -0800
Re: Counted string albert@spenarnc.xs4all.nl (Albert van der Horst) - 2015-01-21 10:54 +0000
Re: Counted string lehs <skydda.barnen@gmail.com> - 2015-01-30 11:18 -0800
Re: Counted string Matthias Koch <matthias.koch@hot.uni-hannover.de> - 2015-01-21 11:58 +0100
Re: Counted string "HAA" <someone@microsoft.com> - 2015-01-22 11:49 +1100
Re: Counted string "Rod Pemberton" <buzz@notnotnontnooatno.cmm> - 2015-01-23 20:17 -0500
Re: Counted string Marek Brunda <marekb@phoenics.org> - 2015-01-26 11:21 -0800
Re: Counted string Mark Wills <markwills1970@gmail.com> - 2015-01-26 12:11 -0800
Re: Counted string "Rod Pemberton" <buzz@notnotnontnooatno.cmm> - 2015-01-26 21:55 -0500
Re: Counted string Julian Fondren <julian.fondren@gmail.com> - 2015-01-26 19:46 -0800
Re: Counted string albert@spenarnc.xs4all.nl (Albert van der Horst) - 2015-01-27 12:07 +0000
Re: Counted string "Rod Pemberton" <buzz@notnotnontnooatno.cmm> - 2015-01-28 20:13 -0500
Re: Counted string anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-01-27 15:43 +0000
Re: Counted string Marek Brunda <marekb@phoenics.org> - 2015-01-27 13:28 -0800
Re: Counted string Elizabeth D Rather <erather@forth.com> - 2015-01-27 13:06 -1000
Re: Counted string anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-01-30 17:33 +0000
Re: Counted string "Rod Pemberton" <buzz@notnotnontnooatno.cmm> - 2015-01-28 20:07 -0500
Re: Counted string "Rod Pemberton" <buzz@notnotnontnooatno.cmm> - 2015-01-28 20:16 -0500
Re: Counted string Coos Haak <chforth@hccnet.nl> - 2015-01-29 03:14 +0100
Re: Counted string Pablo Hugo Reda <pabloreda@gmail.com> - 2015-01-26 12:14 -0800
Re: Counted string "Rod Pemberton" <buzz@notnotnontnooatno.cmm> - 2015-01-26 21:55 -0500
Re: Counted string Ron Aaron <rambamist@gmail.com> - 2015-01-27 06:55 +0200
Re: Counted string "Alex McDonald" <blog@rivadpm.com> - 2015-01-27 14:46 +0000
Re: Counted string "Elizabeth D. Rather" <erather@forth.com> - 2015-01-26 11:25 -1000
csiph-web