From c41287b318da8849ea61cf712a303f0a84da56dd Mon Sep 17 00:00:00 2001 From: "Barton E. Schaefer" Date: Thu, 5 Jun 2014 08:57:40 -0700 Subject: 32716: properly test iconv return values for error conditions --- Src/utils.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'Src') diff --git a/Src/utils.c b/Src/utils.c index 8b512bbd9..59b9435ff 100644 --- a/Src/utils.c +++ b/Src/utils.c @@ -4287,7 +4287,7 @@ zreaddir(DIR *dir, int ignoredots) #if defined(HAVE_ICONV) && defined(__APPLE__) if (!conv_ds) conv_ds = iconv_open("UTF-8", "UTF-8-MAC"); - if (conv_ds) { + if (conv_ds != (iconv_t)(-1)) { /* Force initial state in case re-using conv_ds */ (void) iconv(conv_ds, 0, &orig_name_len, 0, &conv_name_len); @@ -4298,12 +4298,11 @@ zreaddir(DIR *dir, int ignoredots) conv_name_len = orig_name_len; if (iconv(conv_ds, &orig_name_ptr, &orig_name_len, - &conv_name_ptr, &conv_name_len) >= 0) { - if (orig_name_len == 0) { + &conv_name_ptr, &conv_name_len) != (size_t)(-1) && + orig_name_len == 0) { /* Completely converted, metafy and return */ *conv_name_ptr = '\0'; return metafy(conv_name, -1, META_STATIC); - } } /* Error, or conversion incomplete, keep the original name */ } -- cgit 1.4.1 From 32756f78afc81bdc42b47c7bdb522c582b9d896a Mon Sep 17 00:00:00 2001 From: "Barton E. Schaefer" Date: Thu, 5 Jun 2014 21:10:23 -0700 Subject: 32723: add braces around some if/else branches --- ChangeLog | 2 ++ Src/glob.c | 11 +++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) (limited to 'Src') diff --git a/ChangeLog b/ChangeLog index ab953e675..45066e8d2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,7 @@ 2014-06-05 Barton E. Schaefer + * 32723: Src/glob.c: add braces around some if/else branches + * 32716 (via Jun T. 31714): Src/utils.c: properly test iconv return values for error conditions diff --git a/Src/glob.c b/Src/glob.c index c6cb3d2fc..15a5f70b7 100644 --- a/Src/glob.c +++ b/Src/glob.c @@ -462,18 +462,19 @@ scanner(Complist q, int shortcircuit) int errssofar = errsfound; struct dirsav ds; - init_dirsav(&ds); if (!q) return; + init_dirsav(&ds); if ((closure = q->closure)) { /* (foo/)# - match zero or more dirs */ if (q->closure == 2) /* (foo/)## - match one or more dirs */ q->closure = 1; - else + else { scanner(q->next, shortcircuit); if (shortcircuit && shortcircuit == matchct) return; + } } p = q->pat; /* Now the actual matching for the current path section. */ @@ -518,10 +519,11 @@ scanner(Complist q, int shortcircuit) } if (add) { addpath(str, l); - if (!closure || !statfullpath("", NULL, 1)) + if (!closure || !statfullpath("", NULL, 1)) { scanner((q->closure) ? q : q->next, shortcircuit); if (shortcircuit && shortcircuit == matchct) return; + } pathbuf[pathpos = oppos] = '\0'; } } @@ -618,11 +620,12 @@ scanner(Complist q, int shortcircuit) memcpy(subdirs + subdirlen, (char *)&errsfound, sizeof(int)); subdirlen += sizeof(int); - } else + } else { /* if the last filename component, just add it */ insert(fn, 1); if (shortcircuit && shortcircuit == matchct) return; + } } } closedir(lock); -- cgit 1.4.1 From 7f6dc0fe8e3c9aaec8aa295cc4459eabb8f2ada2 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Fri, 6 Jun 2014 21:56:47 +0100 Subject: 32682 with tweaks: Add INC_APPEND_HISTORY_TIME. Revert INC_APPEND_HISTORY behaviour. --- ChangeLog | 5 +++++ Doc/Zsh/options.yo | 30 ++++++++++++++++++++++++------ Src/hist.c | 14 +++++++++----- Src/options.c | 1 + Src/zsh.h | 1 + 5 files changed, 40 insertions(+), 11 deletions(-) (limited to 'Src') diff --git a/ChangeLog b/ChangeLog index 2c44530d7..776e4d980 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2014-06-06 Peter Stephenson + * 32682 with tweaks: Doc/Zsh/options.yo, Src/hist.c, + Src/options.c, Src/zsh.h: INC_APPEND_HISTORY_TIME is new + behaviour, with INC_APPEND_HISTORY reverting to its previous + behaviour. + * Andrew Magee: 32698: Completion/Unix/Command/_hg: show committable files. diff --git a/Doc/Zsh/options.yo b/Doc/Zsh/options.yo index 349946d82..7788cd755 100644 --- a/Doc/Zsh/options.yo +++ b/Doc/Zsh/options.yo @@ -971,6 +971,23 @@ The file will still be periodically re-written to trim it when the number of lines grows 20% beyond the value specified by tt($SAVEHIST) (see also the HIST_SAVE_BY_COPY option). ) +pindex(INC_APPEND_HISTORY_TIME) +pindex(NO_INC_APPEND_HISTORY_TIME) +pindex(INCAPPENDHISTORYTIME) +pindex(NOINCAPPENDHISTORYTIME) +cindex(history, incremental appending to a file with time) +item(tt(INC_APPEND_HISTORY_TIME))( +This option is a variant of tt(INC_APPEND_HISTORY) in which, where +possible, the history entry is written out to the file after the +command is finished, so that the time taken by the command is recorded +correctly in the history file in tt(EXTENDED_HISTORY) format. This +means that the history entry will not be available immediately from +other instances of the shell that are using the same history file. + +This option is only useful if tt(INC_APPEND_HISTORY) and +tt(SHARE_HISTORY) are turned off. The three options should be +considered mutually exclusive. +) pindex(SHARE_HISTORY) pindex(NO_SHARE_HISTORY) pindex(SHAREHISTORY) @@ -981,10 +998,10 @@ item(tt(SHARE_HISTORY) )( This option both imports new commands from the history file, and also causes your typed commands to be appended to the history file (the -latter is like specifying tt(INC_APPEND_HISTORY)). -The history lines are also output with timestamps ala -tt(EXTENDED_HISTORY) (which makes it easier to find the spot where -we left off reading the file after it gets re-written). +latter is like specifying tt(INC_APPEND_HISTORY), which should be turned +off if this option is in effect). The history lines are also output +with timestamps ala tt(EXTENDED_HISTORY) (which makes it easier to find +the spot where we left off reading the file after it gets re-written). By default, history movement commands visit the imported lines as well as the local lines, but you can toggle this on and off with the @@ -994,8 +1011,9 @@ some include them. If you find that you want more control over when commands get imported, you may wish to turn tt(SHARE_HISTORY) off, -tt(INC_APPEND_HISTORY) on, and then manually import -commands whenever you need them using `tt(fc -RI)'. +tt(INC_APPEND_HISTORY) or tt(INC_APPEND_HISTORY_TIME) (see above) on, +and then manually import commands whenever you need them using `tt(fc +-RI)'. ) enditem() diff --git a/Src/hist.c b/Src/hist.c index 1182994a2..64f88f559 100644 --- a/Src/hist.c +++ b/Src/hist.c @@ -935,9 +935,11 @@ hbegin(int dohist) hf = getsparam("HISTFILE"); /* - * For INCAPPENDHISTORY, when interactive, save the history here + * For INCAPPENDHISTORYTIME, when interactive, save the history here * as it gives a better estimate of the times of commands. * + * If INCAPPENDHISTORY is also set we've already done it. + * * If SHAREHISTORY is also set continue to do so in the * standard place, because that's safer about reading and * rewriting history atomically. @@ -950,7 +952,8 @@ hbegin(int dohist) * so that (correctly) nothing happens here. But it shows * I thought about it. */ - if (isset(INCAPPENDHISTORY) && !isset(SHAREHISTORY) && + if (isset(INCAPPENDHISTORYTIME) && !isset(SHAREHISTORY) && + !isset(INCAPPENDHISTORY) && !(histactive & HA_NOINC) && !strin && histsave_stack_pos == 0) savehistfile(hf, 0, HFILE_USE_OPTIONS | HFILE_FAST); } @@ -1378,7 +1381,8 @@ hend(Eprog prog) * For normal INCAPPENDHISTORY case and reasoning, see hbegin(). */ if (isset(SHAREHISTORY) ? histfileIsLocked() : - (isset(INCAPPENDHISTORY) && histsave_stack_pos != 0)) + (isset(INCAPPENDHISTORY) || (isset(INCAPPENDHISTORYTIME) && + histsave_stack_pos != 0))) savehistfile(hf, 0, HFILE_USE_OPTIONS | HFILE_FAST); unlockhistfile(hf); /* It's OK to call this even if we aren't locked */ /* @@ -2542,7 +2546,7 @@ savehistfile(char *fn, int err, int writeflags) } if (writeflags & HFILE_USE_OPTIONS) { if (isset(APPENDHISTORY) || isset(INCAPPENDHISTORY) - || isset(SHAREHISTORY)) + || isset(INCAPPENDHISTORYTIME) || isset(SHAREHISTORY)) writeflags |= HFILE_APPEND | HFILE_SKIPOLD; else histfile_linect = 0; @@ -2578,7 +2582,7 @@ savehistfile(char *fn, int err, int writeflags) tmpfile = NULL; if (err) { if (isset(APPENDHISTORY) || isset(INCAPPENDHISTORY) - || isset(SHAREHISTORY)) + || isset(INCAPPENDHISTORYTIME) || isset(SHAREHISTORY)) zerr("rewriting %s would change its ownership -- skipped", fn); else zerr("rewriting %s would change its ownership -- history not saved", fn); diff --git a/Src/options.c b/Src/options.c index e83dc5839..2163bff4d 100644 --- a/Src/options.c +++ b/Src/options.c @@ -165,6 +165,7 @@ static struct optname optns[] = { {{NULL, "ignoreclosebraces", OPT_EMULATE}, IGNORECLOSEBRACES}, {{NULL, "ignoreeof", 0}, IGNOREEOF}, {{NULL, "incappendhistory", 0}, INCAPPENDHISTORY}, +{{NULL, "incappendhistorytime", 0}, INCAPPENDHISTORYTIME}, {{NULL, "interactive", OPT_SPECIAL}, INTERACTIVE}, {{NULL, "interactivecomments",OPT_BOURNE}, INTERACTIVECOMMENTS}, {{NULL, "ksharrays", OPT_EMULATE|OPT_BOURNE}, KSHARRAYS}, diff --git a/Src/zsh.h b/Src/zsh.h index 620883b81..05d582cda 100644 --- a/Src/zsh.h +++ b/Src/zsh.h @@ -2115,6 +2115,7 @@ enum { IGNORECLOSEBRACES, IGNOREEOF, INCAPPENDHISTORY, + INCAPPENDHISTORYTIME, INTERACTIVE, INTERACTIVECOMMENTS, KSHARRAYS, -- cgit 1.4.1 From 4f4d2b8247ef08e34fe73d91c0a8d8a2eb1f18c7 Mon Sep 17 00:00:00 2001 From: Nikolas Garofil Date: Sat, 7 Jun 2014 13:48:40 -0700 Subject: 32737, 32736 (32741), 32735, 32734, 32733, 32732 (32739): Strict compilation fixes Src/utils.c: properly ifdef declarations Src/zsh_system.h: memmove() should return its dest argument Src/signals.c: define ret before use Src/mem.c: remove unused pointers Src/prototypes.h: use size_t in bcopy() Src/compat.c: fix const declaration inconsistency --- ChangeLog | 16 ++++++++++++++++ Src/compat.c | 2 +- Src/mem.c | 6 +++--- Src/prototypes.h | 2 +- Src/signals.c | 2 +- Src/utils.c | 8 +++++--- Src/zsh_system.h | 5 ++++- 7 files changed, 31 insertions(+), 10 deletions(-) (limited to 'Src') diff --git a/ChangeLog b/ChangeLog index 056ad1f3e..3a304c0ec 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,19 @@ +2014-06-07 Barton E. Schaefer + + * Nikolas Garofil: 32737: Src/utils.c: properly ifdef declarations + + * Nikolas Garofil: 32736 (tweak per 32741): Src/zsh_system.h: + memmove() should return its dest argument + + * Nikolas Garofil: 32735: Src/signals.c: define ret before use + + * Nikolas Garofil: 32734: Src/mem.c: remove unused pointers + + * Nikolas Garofil: 32733: Src/prototypes.h: use size_t in bcopy() + + * Nikolas Garofil: 32732 (tweak per 32739): Src/compat.c: fix + const declaration inconsistency + 2014-06-06 Peter Stephenson * Jun T: 32719: Doc/Zsh/contrib.yo: minor issues. diff --git a/Src/compat.c b/Src/compat.c index cc4e876da..b0bcb6265 100644 --- a/Src/compat.c +++ b/Src/compat.c @@ -37,7 +37,7 @@ char * strstr(const char *s, const char *t) { - char *p1, *p2; + const char *p1, *p2; for (; *s; s++) { for (p1 = s, p2 = t; *p2; p1++, p2++) diff --git a/Src/mem.c b/Src/mem.c index a7f11a62b..f19817723 100644 --- a/Src/mem.c +++ b/Src/mem.c @@ -1508,7 +1508,7 @@ zsfree(char *p) MALLOC_RET_T realloc(MALLOC_RET_T p, MALLOC_ARG_T size) { - struct m_hdr *m = (struct m_hdr *)(((char *)p) - M_ISIZE), *mp, *mt; + struct m_hdr *m = (struct m_hdr *)(((char *)p) - M_ISIZE), *mt; char *r; int i, l = 0; @@ -1524,10 +1524,10 @@ realloc(MALLOC_RET_T p, MALLOC_ARG_T size) /* check if we are reallocating a small block, if we do, we have to compute the size of the block from the sort of block it is in */ for (i = 0; i < M_NSMALL; i++) { - for (mp = NULL, mt = m_small[i]; + for (mt = m_small[i]; mt && (((char *)mt) > ((char *)p) || (((char *)mt) + mt->len) < ((char *)p)); - mp = mt, mt = mt->next); + mt = mt->next); if (mt) { l = M_BSLEN(mt->len); diff --git a/Src/prototypes.h b/Src/prototypes.h index 00988ac4c..e3db4f5ee 100644 --- a/Src/prototypes.h +++ b/Src/prototypes.h @@ -130,5 +130,5 @@ extern char *strerror _((int errnum)); /***************************************************/ #ifndef HAVE_MEMMOVE -extern void bcopy _((const void *, void *, int)); +extern void bcopy _((const void *, void *, size_t)); #endif diff --git a/Src/signals.c b/Src/signals.c index a6eb8038b..cb2b58161 100644 --- a/Src/signals.c +++ b/Src/signals.c @@ -369,7 +369,7 @@ signal_suspend(UNUSED(int sig), int wait_cmd) #ifdef POSIX_SIGNALS # ifdef BROKEN_POSIX_SIGSUSPEND sigprocmask(SIG_SETMASK, &set, &oset); - pause(); + ret = pause(); sigprocmask(SIG_SETMASK, &oset, NULL); # else /* not BROKEN_POSIX_SIGSUSPEND */ ret = sigsuspend(&set); diff --git a/Src/utils.c b/Src/utils.c index 59b9435ff..cef2abef8 100644 --- a/Src/utils.c +++ b/Src/utils.c @@ -2712,8 +2712,11 @@ ztrftimebuf(int *bufsizeptr, int decr) mod_export int ztrftime(char *buf, int bufsize, char *fmt, struct tm *tm) { - int hr12, decr; -#ifndef HAVE_STRFTIME + int hr12; +#ifdef HAVE_STRFTIME + int decr; + char tmp[4]; +#else static char *astr[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; static char *estr[] = @@ -2721,7 +2724,6 @@ ztrftime(char *buf, int bufsize, char *fmt, struct tm *tm) "Aug", "Sep", "Oct", "Nov", "Dec"}; #endif char *origbuf = buf; - char tmp[4]; while (*fmt) diff --git a/Src/zsh_system.h b/Src/zsh_system.h index e68fd62f9..6887a135b 100644 --- a/Src/zsh_system.h +++ b/Src/zsh_system.h @@ -708,7 +708,10 @@ struct timezone { #endif #ifndef HAVE_MEMMOVE -# define memmove(dest, src, len) bcopy((src), (dest), (len)) +# ifndef memmove +static char *zmmv; +# define memmove(dest, src, len) (bcopy((src), zmmv = (dest), (len)), zmmv) +# endif #endif #ifndef offsetof -- cgit 1.4.1