Octavio, How would you propose addressing this issue? I split my monster patch file and reduced it to 31437 lines (roughly 60,000 lines of the patch turned out to be gettext data that didn't get erased in a make clean) to just insert "(char *)" on the 6727 lines of code producing this warning (yes, I counted). String constants are a fact of life and making everything modifiable is impractical. Just by masking the Char * warnings, I found a handful of compiler warnings that pointed to real problems(I will be submitting those patches soon).
Regards, Paul On Wed, 2011-09-07 at 18:12 -0700, Octavio Alvarez wrote: > On Wed, 07 Sep 2011 17:08:08 -0700, Paul Taggart <ptagg...@cinci.rr.com> > wrote: > >> It is wrong. You have to use 'const char*' in places where you use > >> these strings. > >> This enables compiler to store only one copy of identical texts and > >> identifie places where someone tries to modify string constant (it is > >> a bug). I have done this in my branch. > > > > No, this is not a bug. the called functions are looking for a pointer to > > a string (char *). By just providing a quoted string, you are providing > > the function with the entire string, not just the pointer. The compiler > > recognizes this discrepancy and automatically creates the pointer > > By providing a string literal you are providing the function with a > pointer to read-only data. If you ever *ever* try to modify any > character in this region, you will get a segmentation fault. > > > but > > unlike gcc which has the default option -Wno-write-strings, g++ defaults > > to -Wwrite-strings which issues a warning message : "warning: deprecated > > conversion from string constant to ‘char*’" for each occurrence. > > The easy fix would be to add -Wno-write-strings to CXXFLAGS in all of the > > Makefiles (can be set in configure.in) but I'm a bit of a purest who > > believes its better to fix the problem than to mask it. > > I think we all agree on that: -Wno-write-strings is just masking the > problem. However, adding (char *) to deprecated conversions from > (const char *) is actually worse, as it will not only mask the problem but > will also allow some functions to modify potentially immutable strings, > and thus make Cinelerra more crash-prone. > > When you code something like this: > > char * x = "abcde"; > x[3] = '4'; > > g++ warns about the mistake. If you just shut it up by casting it to > (char *) like this: > > char * x = (char *) "abcde"; > x[3] = '4'; > > The compiler will not warn you and your program will still crash! > This is bad! > > The correct fix (in this case only) is actually: > > char * x = strdup("abcde"); > x[3] = '4'; > > But you can not abuse this or you will end up wasting memory badly. > >