setWindowTitleFormat: fix buffer overrun
[nedit-bw.git] / saveSearchHistory-fixes.patch
blob7a1e7da4a7d8aa7e100cdb3da4c059cb7298642a
1 ---
3 source/Makefile.dependencies | 4 +-
4 source/menu.c | 5 ++-
5 source/nedit.h | 2 -
6 source/preferences.c | 10 +++----
7 source/preferences.h | 4 +-
8 source/search.c | 58 ++++++++++++++++++++++++++-----------------
9 6 files changed, 49 insertions(+), 34 deletions(-)
11 diff --quilt old/source/Makefile.dependencies new/source/Makefile.dependencies
12 --- old/source/Makefile.dependencies
13 +++ new/source/Makefile.dependencies
14 @@ -32,7 +32,7 @@ nc.o: nc.c server_common.h ../util/fileU
15 ../util/prefFile.h ../util/system.h ../util/clearcase.h
16 nedit.o: nedit.c nedit.h textBuf.h file.h preferences.h regularExp.h \
17 selection.h tags.h menu.h macro.h server.h window.h interpret.h ops.h \
18 - rbTree.h parse.h help.h help_topic.h ../util/misc.h \
19 + search.h rbTree.h parse.h help.h help_topic.h ../util/misc.h \
20 ../util/printUtils.h ../util/fileUtils.h ../util/getfiles.h
21 preferences.o: preferences.c preferences.h nedit.h textBuf.h text.h \
22 search.h window.h userCmds.h highlight.h highlightData.h help.h \
23 @@ -46,7 +46,7 @@ regexConvert.o: regexConvert.c regexConv
24 regularExp.o: regularExp.c regularExp.h
25 search.o: search.c search.h nedit.h textBuf.h regularExp.h text.h \
26 server.h window.h preferences.h file.h highlight.h ../util/DialogF.h \
27 - ../util/misc.h
28 + ../util/misc.h ../util/utils.h
29 selection.o: selection.c selection.h nedit.h textBuf.h text.h file.h \
30 window.h menu.h server.h ../util/DialogF.h ../util/fileUtils.h
31 server.o: server.c server.h window.h nedit.h textBuf.h file.h selection.h \
32 diff --quilt old/source/menu.c new/source/menu.c
33 --- old/source/menu.c
34 +++ new/source/menu.c
35 @@ -2309,9 +2309,10 @@ static void saveSearchHistoryDefCB(Widge
37 /* Set the preference and make the other windows' menus agree */
38 SetPrefSaveSearchHistory(state);
39 - for (win=WindowList; win!=NULL; win=win->next) {
40 - if (IsTopDocument(win))
41 + for (win = WindowList; win != NULL; win = win->next) {
42 + if (IsTopDocument(win)) {
43 XmToggleButtonSetState(win->saveSearchHistoryDefItem, state, False);
44 + }
48 diff --quilt old/source/preferences.c new/source/preferences.c
49 --- old/source/preferences.c
50 +++ new/source/preferences.c
51 @@ -274,7 +274,7 @@ static struct prefData {
52 int autoIndent; /* style for auto-indent */
53 int autoSave; /* whether automatic backup feature is on */
54 int saveOldVersion; /* whether to preserve a copy of last version */
55 - int saveSearchHistory; /* whether to store search/replace history */
56 + int saveSearchHistory; /* whether to store search/replace history */
57 int searchDlogs; /* whether to show explanatory search dialogs */
58 int searchWrapBeep; /* 1=beep when search restarts at begin/end */
59 int keepSearchDlogs; /* whether to retain find and replace dialogs */
60 @@ -1798,14 +1798,14 @@ int GetPrefSaveOldVersion(void)
61 return PrefData.saveOldVersion;
64 -void SetPrefSaveSearchHistory(int state)
65 +void SetPrefSaveSearchHistory(Boolean state)
67 - setIntPref(&PrefData.saveSearchHistory, state);
68 + setIntPref(&PrefData.saveSearchHistory, !!state);
71 -int GetPrefSaveSearchHistory(void)
72 +Boolean GetPrefSaveSearchHistory(void)
74 - return PrefData.saveSearchHistory;
75 + return (Boolean)!!PrefData.saveSearchHistory;
78 void SetPrefSearchDlogs(int state)
79 diff --quilt old/source/preferences.h new/source/preferences.h
80 --- old/source/preferences.h
81 +++ new/source/preferences.h
82 @@ -59,8 +59,8 @@ void SetPrefWrap(int state);
83 int GetPrefWrap(int langMode);
84 void SetPrefWrapMargin(int margin);
85 int GetPrefWrapMargin(void);
86 -void SetPrefSaveSearchHistory(int state);
87 -int GetPrefSaveSearchHistory(void);
88 +void SetPrefSaveSearchHistory(Boolean state);
89 +Boolean GetPrefSaveSearchHistory(void);
90 void SetPrefShowWrapMargin(int state);
91 int GetPrefShowWrapMargin(void);
92 void SetPrefSearchDlogs(int state);
93 diff --quilt old/source/search.c new/source/search.c
94 --- old/source/search.c
95 +++ new/source/search.c
96 @@ -2931,6 +2931,10 @@ void BeginISearch(WindowInfo *window, in
98 TempShowISearch(window, TRUE);
99 XmProcessTraversal(window->iSearchText, XmTRAVERSE_CURRENT);
101 + /* Refresh search/replace history where two sessions overwrite each
102 + other's changes in the history file. */
103 + ReadSearchHistory();
107 @@ -4706,9 +4710,10 @@ static void enableFindAgainCmds(void)
109 WindowInfo *w;
111 - for (w=WindowList; w!=NULL; w=w->next) {
112 - if (!IsTopDocument(w))
113 + for (w = WindowList; w != NULL; w = w->next) {
114 + if (!IsTopDocument(w)) {
115 continue;
117 XtSetSensitive(w->findAgainItem, True);
118 XtSetSensitive(w->replaceFindAgainItem, True);
119 XtSetSensitive(w->replaceAgainItem, True);
120 @@ -4737,8 +4742,9 @@ void WriteSearchHistory(void)
121 int i;
123 /* If the Save Search-History option is disabled, just return */
124 - if (!GetPrefSaveSearchHistory())
125 + if (!GetPrefSaveSearchHistory()) {
126 return;
129 /* open the file */
130 if ((fp = fopen(fullName, "w")) == NULL) {
131 @@ -4750,8 +4756,9 @@ void WriteSearchHistory(void)
132 beginning of file.
133 By calling ftruncate(), we discard the old contents and avoid
134 trailing garbage in the file if the new contents is shorter. */
135 - if ((fp = fopen(fullName, "r+")) == NULL)
136 + if ((fp = fopen(fullName, "r+")) == NULL) {
137 return;
139 if (ftruncate(fileno(fp), 0) != 0) {
140 fclose(fp);
141 return;
142 @@ -4766,9 +4773,9 @@ void WriteSearchHistory(void)
143 searchStr = SearchHistory[historyIndex(i)];
144 replaceStr = ReplaceHistory[historyIndex(i)];
145 fprintf(fp, "%d:%u:%u\n%s\n%s\n",
146 - SearchTypeHistory[historyIndex(i)],
147 - (unsigned)strlen(searchStr), (unsigned)strlen(replaceStr),
148 - searchStr, replaceStr);
149 + SearchTypeHistory[historyIndex(i)],
150 + (unsigned)strlen(searchStr), (unsigned)strlen(replaceStr),
151 + searchStr, replaceStr);
153 fclose(fp);
155 @@ -4796,8 +4803,9 @@ void ReadSearchHistory(void)
156 FILE *fp;
158 /* If the save search history option is disabled, just return */
159 - if (!GetPrefSaveSearchHistory())
160 + if (!GetPrefSaveSearchHistory()) {
161 return;
164 /* Stat history file to see whether someone touched it after this
165 session last changed it. */
166 @@ -4811,15 +4819,17 @@ void ReadSearchHistory(void)
168 } else {
169 /* stat() failed, probably for non-exiting history database. */
170 - if (ENOENT != errno)
171 + if (ENOENT != errno) {
172 fprintf(stderr, "NEdit: Error reading file %s (%s)\n",
173 - fullName, strerror(errno));
174 + fullName, strerror(errno));
176 return;
179 /* open the file */
180 - if ((fp = fopen(fullName, "r")) == NULL)
181 + if ((fp = fopen(fullName, "r")) == NULL) {
182 return;
185 /* Clear previous list */
186 while (0 != NHist) {
187 @@ -4848,9 +4858,9 @@ void ReadSearchHistory(void)
188 break;
191 - SearchTypeHistory[HistStart]=type;
192 + SearchTypeHistory[HistStart] = type;
193 if (type < 0 || type >= N_SEARCH_TYPES
194 - || srchLen > SEARCHMAX || replLen > SEARCHMAX) {
195 + || srchLen > SEARCHMAX || replLen > SEARCHMAX) {
196 fprintf(stderr, "NEdit: Invalid values in file %s\n", fullName);
197 break;
199 @@ -4860,42 +4870,45 @@ void ReadSearchHistory(void)
200 if (NHist == MAX_SEARCH_HISTORY) {
201 XtFree(SearchHistory[HistStart]);
202 XtFree(ReplaceHistory[HistStart]);
203 - } else
204 + } else {
205 NHist++;
208 /* read and store search-string */
209 SearchHistory[HistStart] = XtMalloc(srchLen+1);
210 if (fread(SearchHistory[HistStart], 1, srchLen + 1, fp) != srchLen + 1
211 - || SearchHistory[HistStart][srchLen] != '\n') {
212 + || SearchHistory[HistStart][srchLen] != '\n') {
213 fprintf(stderr, "NEdit: Error reading file %s (%s)\n",
214 fullName, strerror(errno));
215 XtFree(SearchHistory[HistStart]);
216 NHist--;
217 break;
219 - SearchHistory[HistStart][srchLen]='\0';
220 + SearchHistory[HistStart][srchLen] = '\0';
222 /* read and store replace-string */
223 ReplaceHistory[HistStart] = XtMalloc(replLen+1);
224 if (fread(ReplaceHistory[HistStart], 1, replLen + 1, fp) != replLen + 1
225 - || ReplaceHistory[HistStart][replLen] != '\n') {
226 + || ReplaceHistory[HistStart][replLen] != '\n') {
227 fprintf(stderr, "NEdit: Error reading file %s (%s)\n",
228 - fullName, strerror(errno));
229 + fullName, strerror(errno));
230 XtFree(SearchHistory[HistStart]);
231 XtFree(ReplaceHistory[HistStart]);
232 NHist--;
233 break;
235 - ReplaceHistory[HistStart][replLen]='\0';
236 + ReplaceHistory[HistStart][replLen] = '\0';
238 - if (++HistStart >= MAX_SEARCH_HISTORY)
239 + if (++HistStart >= MAX_SEARCH_HISTORY) {
240 HistStart = 0;
243 fclose(fp);
245 /* If there are history items, enable Find/Replace Again commands */
246 - if (NHist)
247 + if (NHist) {
248 enableFindAgainCmds();
253 @@ -4947,8 +4960,9 @@ static void saveSearchHistory(const char
254 currentItemIsIncremental = isIncremental;
256 /* Enable Find/Replace Again commands on first call */
257 - if (NHist == 0)
258 + if (NHist == 0) {
259 enableFindAgainCmds();
262 /* Refresh search/replace history where two sessions overwrite each
263 other's changes in the history file. */
264 diff --quilt old/source/nedit.h new/source/nedit.h
265 --- old/source/nedit.h
266 +++ new/source/nedit.h
267 @@ -406,7 +406,7 @@ typedef struct _WindowInfo {
268 Widget searchDlogsDefItem;
269 Widget beepOnSearchWrapDefItem;
270 Widget keepSearchDlogsDefItem;
271 - Widget saveSearchHistoryDefItem;
272 + Widget saveSearchHistoryDefItem;
273 Widget searchWrapsDefItem;
274 Widget showCursorlineItem;
275 Widget appendLFItem;