aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcmay <cmay@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>2006-07-19 01:57:01 +0000
committercmay <cmay@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>2006-07-19 01:57:01 +0000
commit527a8de007076606a3a4f5add720e816bee05aed (patch)
tree527e5cf278e649954d7a809c76a1097acd8f2665
parent2a17bec28b7cb59937f60998e8fed628108a9a38 (diff)
downloadlcd4linux-527a8de007076606a3a4f5add720e816bee05aed.tar.gz
[lcd4linux @ 2006-07-19 01:57:01 by cmay]
fixed double read of last line in file git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@674 3ae390bd-cb1e-0410-b409-cd5a39f66f1f
Diffstat (limited to '')
-rw-r--r--plugin_file.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/plugin_file.c b/plugin_file.c
index 24ac815..368eec9 100644
--- a/plugin_file.c
+++ b/plugin_file.c
@@ -1,4 +1,4 @@
-/* $Id: plugin_file.c,v 1.1 2006/02/19 15:42:19 reinelt Exp $
+/* $Id: plugin_file.c,v 1.2 2006/07/19 01:57:01 cmay Exp $
*
* plugin to perform simple file operations
*
@@ -23,6 +23,9 @@
*
*
* $Log: plugin_file.c,v $
+ * Revision 1.2 2006/07/19 01:57:01 cmay
+ * fixed double read of last line in file
+ *
* Revision 1.1 2006/02/19 15:42:19 reinelt
* file plugin from Chris Maj
*
@@ -69,7 +72,7 @@ static void my_readline(RESULT * result, RESULT * arg1, RESULT * arg2)
error("readline couldn't open file '%s'", R2S(arg1));
} else {
i = 0;
- while (!feof(fp) && i < reqline) {
+ while (!feof(fp) && i++ < reqline) {
fgets(val2, sizeof(val2), fp);
size = strcspn(val2, "\n");
strncpy(value, val2, size);
@@ -80,11 +83,10 @@ static void my_readline(RESULT * result, RESULT * arg1, RESULT * arg2)
fgets(val2, sizeof(val2), fp);
pos = strchr(val2, '\n');
}
- i++;
}
fclose(fp);
- if (i < reqline) {
- error("readline requested line %d but file only had %d lines", reqline, i);
+ if (i <= reqline) {
+ error("readline requested line %d but file only had %d lines", reqline, i - 1);
value[0] = '\0';
}
}