From bb69bf6964aed63092600b94e33d818d718b9b0d Mon Sep 17 00:00:00 2001 From: Jan Vales Date: Mon, 30 Jan 2012 11:34:41 +0100 Subject: [PATCH] getopt fix: will now fail when reading more than $file.size from $file. --- prefix/prefix.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/prefix/prefix.c b/prefix/prefix.c index 57304b9..77c7f93 100644 --- a/prefix/prefix.c +++ b/prefix/prefix.c @@ -71,9 +71,13 @@ int main (int argc, char* argv[]) { struct stat st; stat(filename, &st); size = st.st_size; - if (n <= 0 || n > size){ + if (n == 0){ n = size; } + if (n < 0 || n > size){ + fprintf (stderr, "Cannot read %li numbers from \"%s\" - only has %li bytes.\n",n,filename,st.st_size); + usage(); + } }else{ fprintf (stderr, "File %s does not exist.\n", filename); usage(); -- 2.43.0