Thread View: comp.lang.c++.leda
6 messages
6 total messages
Started by Peter Haumer
Mon, 31 Jul 1995 16:04
STRING_CONSTRUCTOR limits strings to 512 byte
Author: Peter Haumer
Date: Mon, 31 Jul 1995 16:04
Date: Mon, 31 Jul 1995 16:04
20 lines
1128 bytes
1128 bytes
Hi. The macro STRING_CONSTRUCTOR in _string.c limits the size of strings to 512 bytes. I don't think that this is necessary. Does anybody know, why it is is implemenented in this way? There should be at least an assertion for a precondition or a size check in the macro. Programs which want to construct longer strings with varargs just crash/core dump. Thanks in advance, Peter. -- ____________________________________________________________________________ Peter Haumer haumer@informatik.rwth-aachen.de Lehrstuhl Informatik V Tel:+49-(0)241-80-21510 Fax:+49-(0)241-8888-321 RWTH Aachen Ahornstr.55, 52056 Aachen, (Germany)
Re: STRING_CONSTRUCTOR limits strings to 512 byte
Author: David F. Skoll
Date: Mon, 31 Jul 1995 17:45
Date: Mon, 31 Jul 1995 17:45
39 lines
1896 bytes
1896 bytes
In article <3viuuv$dcl@news.rwth-aachen.de>, Peter Haumer
(haumer@informatik.rwth-aachen.de) wrote:
> The macro STRING_CONSTRUCTOR in _string.c limits the size of strings to
> 512 bytes. I don't think that this is necessary. Does anybody know, why it
> is is implemenented in this way?
Because it's implemented incorrectly. Even worse, "512" is hard-coded.
It should be a macro, at least.
> There should be at least an assertion for a precondition or a size check
> in the macro. Programs which want to construct longer strings with varargs
> just crash/core dump.
The only *portable* way (other than writing one's on sprintf-like
function) to handle very long strings is to write them to a file (with
vfprintf...) and then read the file back into memory. The
sprintf... functions have no provisions for checking buffer overflow,
which makes checking the precondition very difficult.
A nicer solution, IMO, is for LEDA authors to define left-shift
operators like this:
string & string::operator<<(int i) { ... }
string & string::operator<<(double d) { ... }
etc...
Then you could say:
string s;
int a=4, b=6;
s << a << " times " << b << " equals " << a*b;
which would append to s. This is type-safe and more "C++-like".
--
David F. Skoll
<a HREF="http://www.doe.carleton.ca/students/dfs/">
Click here for my home page</a> "Query two pi" on typewriter.
Bug in STRING_CONSTRUCTOR
Author: David F. Skoll
Date: Mon, 31 Jul 1995 18:23
Date: Mon, 31 Jul 1995 18:23
7 lines
745 bytes
745 bytes
I discovered another bug in STRING_CONSTRUCTOR: After the call to vsprintf(), there should be a va_end call. -- David F. Skoll <a HREF="http://www.doe.carleton.ca/students/dfs/"> Click here for my home page</a> "Query two pi" on typewriter.
More wild and wooly LEDA string stuff...
Author: David F. Skoll
Date: Mon, 31 Jul 1995 18:52
Date: Mon, 31 Jul 1995 18:52
21 lines
1003 bytes
1003 bytes
Guess what this program does:
#include <LEDA/string.h>
#include <iostream.h>
int main()
{
string s("Foo Bar Baz");
char const *pstr;
pstr = ~s;
cout << pstr << endl;
}
I think I'll just weep wearily into a good programming-style book...
This takes operator-overloading to absurd new depths.
--
David F. Skoll
<a HREF="http://www.doe.carleton.ca/students/dfs/">
Click here for my home page</a> "Query two pi" on typewriter.
Re: STRING_CONSTRUCTOR limits strings to 512 byte
Author: R. van der Wal
Date: Thu, 03 Aug 1995 12:34
Date: Thu, 03 Aug 1995 12:34
50 lines
2396 bytes
2396 bytes
In article <DCLDB9.ArI@cunews.carleton.ca> dfs@doe.carleton.ca (David F. Skoll) writes:
>From: dfs@doe.carleton.ca (David F. Skoll)
>Subject: Re: STRING_CONSTRUCTOR limits strings to 512 byte
>Date: Mon, 31 Jul 1995 17:45:09 GMT
>In article <3viuuv$dcl@news.rwth-aachen.de>, Peter Haumer
>(haumer@informatik.rwth-aachen.de) wrote:
>> The macro STRING_CONSTRUCTOR in _string.c limits the size of strings to
>> 512 bytes. I don't think that this is necessary. Does anybody know, why it
>> is is implemenented in this way?
>Because it's implemented incorrectly. Even worse, "512" is hard-coded.
>It should be a macro, at least.
>> There should be at least an assertion for a precondition or a size check
>> in the macro. Programs which want to construct longer strings with varargs
>> just crash/core dump.
>The only *portable* way (other than writing one's on sprintf-like
>function) to handle very long strings is to write them to a file (with
>vfprintf...) and then read the file back into memory. The
>sprintf... functions have no provisions for checking buffer overflow,
>which makes checking the precondition very difficult.
>A nicer solution, IMO, is for LEDA authors to define left-shift
>operators like this:
>string & string::operator<<(int i) { ... }
>string & string::operator<<(double d) { ... }
>etc...
>Then you could say:
>string s;
>int a=4, b=6;
>s << a << " times " << b << " equals " << a*b;
>which would append to s. This is type-safe and more "C++-like".
>--
>David F. Skoll
><a HREF="http://www.doe.carleton.ca/students/dfs/">
>Click here for my home page</a> "Query two pi" on typewriter.
The latter suggestion is actually implemented in classes strstream and
ostrstream. Being part of the C++ standard library, they are probably
preferable to building your own string extensions for this purpose.
Ron van der Wal.
Re: STRING_CONSTRUCTOR limits strings to 512 byte
Author: Thomas Malik
Date: Tue, 08 Aug 1995 14:22
Date: Tue, 08 Aug 1995 14:22
58 lines
3046 bytes
3046 bytes
In article <DCLDB9.ArI@cunews.carleton.ca>, dfs@doe.carleton.ca (David F. Skoll) writes:
|> In article <3viuuv$dcl@news.rwth-aachen.de>, Peter Haumer
|> (haumer@informatik.rwth-aachen.de) wrote:
|>
|> > The macro STRING_CONSTRUCTOR in _string.c limits the size of strings to
|> > 512 bytes. I don't think that this is necessary. Does anybody know, why it
|> > is is implemenented in this way?
|> ...
|> A nicer solution, IMO, is for LEDA authors to define left-shift
|> operators like this:
|>
|> string & string::operator<<(int i) { ... }
|> string & string::operator<<(double d) { ... }
|> etc...
|>
|> Then you could say:
|>
|> string s;
|> int a=4, b=6;
|> s << a << " times " << b << " equals " << a*b;
|>
|> which would append to s. This is type-safe and more "C++-like".
|>
|> --
|> David F. Skoll
|> <a HREF="http://www.doe.carleton.ca/students/dfs/">
|> Click here for my home page</a> "Query two pi" on typewriter.
|>
Why don't you simply use the strstream class ? It's much more elegant (i.e. it
allocates it's own memory as needed) than LEDA's printf-like Constructors, and
i think it's pretty standard in the C++ world.
I've just looked over the code in _string.cc , it's the most ugly stuff I've
seen so far (and i've produced many ugly things in my lifetime ...). I think
working with fixed sized arrays for creation/formatting is generally a stupid
idea. They've got so many beautiful data structures, why don't they simply keep a
list of fixed size buffers and cat them together when reading/construction is
complete ?
Besides this, i like the LEDA data types very much, especially the list/graph
stuff. They've just better put some more work into the basics & into Makefile/
configuration stuff (when i get a LEDA version, i don't even try to compile with
their provided Makefiles, i throw them away just after unpacking ... )
--
===============================================================================
|
_/_/_/_/_/_/_/_/_/_/_/ _/ _/_/ |
_/ _/_/ _/ _/ | Thomas Malik
_/ _/ _/ _/ _/ | malik@serv-400.dfki.uni-kl.de
_/ _/ _/ _/ | malik@sun.rhrk.uni-kl.de
_/ _/ _/ | Berliner Str. 5-11
_/ _/ _/ | 6750 Kaiserlautern
_/ _/ _/ | (0631) 79868
_/ _/ _/ _/ _/ |
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads