summaryrefslogtreecommitdiff
path: root/Src/Modules/datetime.c
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2003-10-06 22:46:24 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2003-10-06 22:46:24 +0000
commited6a7ba60e87e1fd4b5c504d82c348e8dc415117 (patch)
tree97be429c165b5eff0b5ad4102a618deec333eac7 /Src/Modules/datetime.c
parentbbc409eefece558f9b24ea6960e15c0c3468422a (diff)
downloadzsh-ed6a7ba60e87e1fd4b5c504d82c348e8dc415117.tar.gz
zsh-ed6a7ba60e87e1fd4b5c504d82c348e8dc415117.zip
19168: Various problems with size of buffers and pointer usage in ztrftime
Diffstat (limited to 'Src/Modules/datetime.c')
-rw-r--r--Src/Modules/datetime.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/Src/Modules/datetime.c b/Src/Modules/datetime.c
index d10274f0d..383f748b5 100644
--- a/Src/Modules/datetime.c
+++ b/Src/Modules/datetime.c
@@ -35,10 +35,9 @@ static int
bin_strftime(char *nam, char **argv, Options ops, int func)
{
int bufsize, x;
- char *endptr = NULL, *buffer = NULL;
+ char *endptr = NULL, *buffer;
time_t secs;
struct tm *t;
- int size;
secs = (time_t)strtoul(argv[1], &endptr, 10);
if (secs == ULONG_MAX) {
@@ -51,15 +50,17 @@ bin_strftime(char *nam, char **argv, Options ops, int func)
t = localtime(&secs);
bufsize = strlen(argv[0]) * 2;
+ buffer = zalloc(bufsize);
- for (x=1;x<4;x++) {
- buffer = zrealloc(buffer, bufsize * x);
- size = ztrftime(buffer, bufsize * x, argv[0], t);
- if (size) x = 4;
+ for (x=0; x < 4; x++) {
+ if (ztrftime(buffer, bufsize, argv[0], t))
+ break;
+ buffer = zrealloc(buffer, bufsize *= 2);
}
printf("%s\n", buffer);
-
+ zfree(buffer, bufsize);
+
return 0;
}