summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohannes Hofmann <Johannes.Hofmann@gmx.de>2005-08-15 12:01:08 +0100
committerJohannes Hofmann <Johannes.Hofmann@gmx.de>2005-08-15 12:01:08 +0100
commit8d7e0aaa20dff413fdc9747b842015664dae6cac (patch)
tree3b8348310457e80c426ddfe4b800110255083283 /src
parent2c264dbb85f64221f20cf93ebdd724dab881b998 (diff)
add check to avoid saving to input image file
Diffstat (limited to 'src')
-rw-r--r--src/GipfelWidget.cxx15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/GipfelWidget.cxx b/src/GipfelWidget.cxx
index d2fe69c..44134f8 100644
--- a/src/GipfelWidget.cxx
+++ b/src/GipfelWidget.cxx
@@ -28,6 +28,7 @@
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>
+#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include <math.h>
@@ -147,12 +148,26 @@ GipfelWidget::save_image(char *file) {
char buf[1024];
int status;
size_t n;
+ struct stat in_stat, out_stat;
if (img_file == NULL) {
fprintf(stderr, "Nothing to save\n");
return 1;
}
+ if (stat(img_file, &in_stat) != 0) {
+ perror("stat");
+ return 1;
+ }
+
+ if (stat(file, &out_stat) == 0) {
+ if (in_stat.st_ino == out_stat.st_ino) {
+ fprintf(stderr, "Input image %s and output image %s are the same file\n",
+ img_file, file);
+ return 1;
+ }
+ }
+
out = fopen(file, "w");
if (out == NULL) {
perror("fopen");