projects
/
pspp
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
psppire_data_window: Don't crash when trying to delete cases when none are selected
[pspp]
/
utilities
/
pspp-convert.c
diff --git
a/utilities/pspp-convert.c
b/utilities/pspp-convert.c
index ce5fd875eace83ad57692bef1f8e11ee9fb25bb9..f21e5bdb8b907cb51a25a331d9311f436fc743e5 100644
(file)
--- a/
utilities/pspp-convert.c
+++ b/
utilities/pspp-convert.c
@@
-1,5
+1,5
@@
/* PSPP - a program for statistical analysis.
/* PSPP - a program for statistical analysis.
- Copyright (C) 2013, 2014, 2015 Free Software Foundation, Inc.
+ Copyright (C) 2013, 2014, 2015
, 2016
Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@
-26,6
+26,7
@@
#include "data/casereader.h"
#include "data/casewriter.h"
#include "data/csv-file-writer.h"
#include "data/casereader.h"
#include "data/casewriter.h"
#include "data/csv-file-writer.h"
+#include "data/dictionary.h"
#include "data/encrypted-file.h"
#include "data/file-name.h"
#include "data/por-file-writer.h"
#include "data/encrypted-file.h"
#include "data/file-name.h"
#include "data/por-file-writer.h"
@@
-46,7
+47,7
@@
static void usage (void);
static void usage (void);
-static
void
decrypt_file (struct encrypted_file *enc,
+static
bool
decrypt_file (struct encrypted_file *enc,
const struct file_handle *input_filename,
const struct file_handle *output_filename,
const char *password);
const struct file_handle *input_filename,
const struct file_handle *output_filename,
const char *password);
@@
-58,14
+59,14
@@
main (int argc, char *argv[])
const char *output_filename;
long long int max_cases = LLONG_MAX;
const char *output_filename;
long long int max_cases = LLONG_MAX;
- struct dictionary *dict;
+ struct dictionary *dict
= NULL
;
struct casereader *reader;
struct casereader *reader;
- struct file_handle *input_fh;
+ struct file_handle *input_fh
= NULL
;
const char *encoding = NULL;
struct encrypted_file *enc;
const char *output_format = NULL;
const char *encoding = NULL;
struct encrypted_file *enc;
const char *output_format = NULL;
- struct file_handle *output_fh;
+ struct file_handle *output_fh
= NULL
;
struct casewriter *writer;
const char *password = NULL;
struct casewriter *writer;
const char *password = NULL;
@@
-125,7
+126,7
@@
main (int argc, char *argv[])
exit (EXIT_SUCCESS);
default:
exit (EXIT_SUCCESS);
default:
-
exit (EXIT_FAILURE)
;
+
goto error
;
}
}
}
}
@@
-163,15
+164,16
@@
main (int argc, char *argv[])
"format"));
}
"format"));
}
- decrypt_file (enc, input_fh, output_fh, password);
+ if (! decrypt_file (enc, input_fh, output_fh, password))
+ goto error;
+
goto exit;
}
reader = any_reader_open_and_decode (input_fh, encoding, &dict, NULL);
if (reader == NULL)
goto exit;
}
reader = any_reader_open_and_decode (input_fh, encoding, &dict, NULL);
if (reader == NULL)
- exit (1);
-
+ goto error;
if (!strcmp (output_format, "csv") || !strcmp (output_format, "txt"))
{
if (!strcmp (output_format, "csv") || !strcmp (output_format, "txt"))
{
@@
-201,6
+203,8
@@
main (int argc, char *argv[])
output_filename);
NOT_REACHED ();
}
output_filename);
NOT_REACHED ();
}
+ if (!writer)
+ error (1, 0, _("%s: error opening output file"), output_filename);
for (i = 0; i < max_cases; i++)
{
for (i = 0; i < max_cases; i++)
{
@@
-219,13
+223,25
@@
main (int argc, char *argv[])
error (1, 0, _("%s: error writing output file"), output_filename);
exit:
error (1, 0, _("%s: error writing output file"), output_filename);
exit:
+ dict_destroy (dict);
+ fh_unref (output_fh);
+ fh_unref (input_fh);
fh_done ();
i18n_done ();
return 0;
fh_done ();
i18n_done ();
return 0;
+
+error:
+ dict_destroy (dict);
+ fh_unref (output_fh);
+ fh_unref (input_fh);
+ fh_done ();
+ i18n_done ();
+
+ return 1;
}
}
-static
void
+static
bool
decrypt_file (struct encrypted_file *enc,
const struct file_handle *ifh,
const struct file_handle *ofh,
decrypt_file (struct encrypted_file *enc,
const struct file_handle *ifh,
const struct file_handle *ofh,
@@
-240,7
+256,7
@@
decrypt_file (struct encrypted_file *enc,
{
password = getpass ("password: ");
if (password == NULL)
{
password = getpass ("password: ");
if (password == NULL)
-
exit (1)
;
+
return false
;
}
if (!encrypted_file_unlock (enc, password))
}
if (!encrypted_file_unlock (enc, password))
@@
-270,6
+286,8
@@
decrypt_file (struct encrypted_file *enc,
if (fflush (out) == EOF)
error (1, errno, ("%s: write error"), output_filename);
fn_close (ofh, out);
if (fflush (out) == EOF)
error (1, errno, ("%s: write error"), output_filename);
fn_close (ofh, out);
+
+ return true;
}
static void
}
static void