summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEduardo Chappa <chappa@washington.edu>2021-11-23 10:53:59 -0700
committerEduardo Chappa <chappa@washington.edu>2021-11-23 10:53:59 -0700
commitbc15b12b7f13ec9c9cd855aae0e62be4d0ef9e31 (patch)
tree3212a2e6a71b66398adadcbad503ee2595e39966
parent9b7d799cadf5d17b408b52d948bfb05d96e01c12 (diff)
downloadalpine-bc15b12b7f13ec9c9cd855aae0e62be4d0ef9e31.tar.xz
* In some systems the size of a directory is the sum of the sizes of
all files contained in it, so sbuf.st_size might be too large and the malloc() might fail with error ENOMEM. Since this is just the list of files, and not the contents of the files, let us start with a small amount and resize when necessary. Reported by Sebasting Knust.
-rw-r--r--pico/osdep/filesys.c12
-rw-r--r--pith/pine.hlp2
2 files changed, 12 insertions, 2 deletions
diff --git a/pico/osdep/filesys.c b/pico/osdep/filesys.c
index af08726b..9d775d14 100644
--- a/pico/osdep/filesys.c
+++ b/pico/osdep/filesys.c
@@ -317,8 +317,18 @@ getfnames(char *dn, char *pat, int *n, char *e, size_t elen)
/*
* We'd like to use 512 * st_blocks as an initial estimate but
* some systems have a stat struct with no st_blocks in it.
+ *
+ * In some systems the size of a directory is the sum of the
+ * sizes of all files contained in it, so sbuf.st_size might
+ * be too large and the malloc() might fail with error ENOMEM.
+ * Since this is just the list of files, and not the contents
+ * of the files, let us start with a small amount and resize
+ * when necessary. Reported by Sebasting Knust. Of course the
+ * correct solution is to read the directory twice, but keeping
+ * realloc()ing as needed also solves the problem in a less
+ * elegant way.
*/
- avail = alloced = MAX(sbuf.st_size, incr);
+ avail = alloced = 4096;
if((sbuf.st_mode&S_IFMT) != S_IFDIR){
if(e)
snprintf(e, elen, _("Not a directory: \"%s\""), dn);
diff --git a/pith/pine.hlp b/pith/pine.hlp
index cc8c8f55..e9fee1cd 100644
--- a/pith/pine.hlp
+++ b/pith/pine.hlp
@@ -140,7 +140,7 @@ with help text for the config screen and the composer that didn't have any
reasonable place to be called from.
Dummy change to get revision in pine.hlp
============= h_revision =================
-Alpine Commit 621 2021-11-22 18:19:28
+Alpine Commit 622 2021-11-23 10:53:56
============= h_news =================
<HTML>
<HEAD>