Well,
I kind of expected this flag to be turned on and then when I found out what was the problem I remembered turning this off because of some third party library in the project when I was moving it from OS9 to OSX.
The project in question is almost 20 years old. The module that was messing up the strings was written by my friend some 15 years ago and included in this project in 2003. The fact remains that the project is my responsibility and that 10 years ago I went trough the friends part line by line, fixing things I didn't like, but somehow I missed the lines that were trashing the static string.
The bigger mystery is why that thing worked all these years. This is why I assumed the code is ok and that maybe I have the problem with compiler/linker. In the hindsight, my assumption is almost
hilarious.
Igor --- On Mon, 10/1/12, Wim Lewis <email@hidden> wrote: From: Wim Lewis <email@hidden> Subject: Re: Very strange problem, static strings related To: "Igor Delovski" <email@hidden>, "xcode-users list" <email@hidden> Date: Monday, October 1, 2012, 9:46 PM
On 27 Sep 2012, at 8:05 PM, Igor Delovski wrote: As I got this message from the list, it became "someone else's problem" and as I read it, the string "912" became obviously Sptember of this year and then I found the problem in a second. A function like
this:
void Something (..., char *aDate, ...) { if (!aDate[0]) strcpy (aDate, GetMeMonthYear()); ... }
And it was called like this: Something (..., "", ...);
Sorry to bother you all with nothing. |
For what it's worth, the default compiler settings for new projects make C string literals unwritable. Old code sometimes depends on being able to write to them, and presumably your project is being built with the -fwritable-strings flag for compatibility. If you don't need to be able to modify string constants, you should probably disable -fwritable-strings — it will save you from hassles like this and will make your program (slightly) more memory-efficient.
(If you *do* need to be able
to modify string constants, I strongly recommend turning off -fwritable-strings anyway and fixing your code to use "char foo[...]", malloc, or some other way of creating a writable buffer.)
|