Corrected segfault on --reset usage option.

This commit is contained in:
Thomas Touhey 2018-04-25 19:24:32 +02:00
parent d520bb9685
commit ecfc8f31ad
No known key found for this signature in database
GPG Key ID: 2ECEB0517AD947FB
3 changed files with 47 additions and 21 deletions

View File

@ -34,20 +34,25 @@ int CASIO_EXPORT casio_setlink(casio_link_t *handle,
int err; casio_streamattrs_t attrs;
unsigned int speed; int stopbits, parity;
/* make checks */
/* Make checks. */
chk_handle(handle);
chk_seven(handle);
chk_active(handle);
/* check settings. */
/* Check settings.
* If we are not on a serial stream, this ain't gonna work. */
if (casio_get_attrs(handle->casio_link_stream, &attrs))
return (casio_error_op);
attrs.casio_streamattrs_speed = uattrs->casio_streamattrs_speed;
attrs.casio_streamattrs_flags =
( attrs.casio_streamattrs_flags & ~MPARSTOP) |
(uattrs->casio_streamattrs_flags & MPARSTOP);
/* get raw information for the command. */
/* Get raw information for the command. */
speed = attrs.casio_streamattrs_speed;
stopbits = attrs.casio_streamattrs_flags & CASIO_TWOSTOPBITS ? 2 : 1;
parity = (~attrs.casio_streamattrs_flags & CASIO_PARENB) ? 0

View File

@ -477,9 +477,11 @@ int parse_args(int ac, char **av, args_t *args)
}
/* set serial settings */
if (rst)
if (rst) {
args->do_the_set = 1;
else if (s_set) {
args->set = &args->_set;
casio_make_attrs(&args->_set, NULL);
} else if (s_set) {
args->do_the_set = 1;
if (args->com) args->set = &args->_set;
if (casio_make_attrs(&args->_set, s_set)) {

View File

@ -20,26 +20,31 @@
#include <stdlib.h>
#include <string.h>
/* ************************************************************************** */
/* Error messages */
/* ************************************************************************** */
/* ---
* Error messages.
* --- */
/* Couldn't initialize connexion with the calculator. */
static const char error_noconnexion[] =
"Could not connect to the calculator.\n"
"- Is it plugged in and in receive mode?\n"
"- Have you tried changing the cable?\n";
/* Calculator was disconnected. */
static const char error_disconnected[] =
"Lost connexion to the calculator!\n"
"Please reconnect the calculator, rerun receive mode and try again.\n";
/* Calculator was found but program wasn't allowed to communicate with it. */
static const char error_noaccess[] =
"Could not get access to the calculator.\n"
"Install the appropriate udev rule, or run as root.\n";
/* Command was unsupported. */
static const char error_unsupported[] =
"The command is unsupported by the calculator.\n"
"- Does the calculator have mass storage?\n"
@ -47,10 +52,12 @@ static const char error_unsupported[] =
"- Is it in Receive Mode (and not in OS Update)?\n";
/* The device didn't exist. */
static const char error_unsupported_device[] =
"Device '%s' is not supported by the device.\n";
/* The calculator acted in an unplanned way. */
static const char error_unplanned[] =
"The calculator didn't act as planned.\n"
"Stop receive mode on calculator and start it again before re-running " \
@ -58,22 +65,26 @@ static const char error_unplanned[] =
"Error was: %s\n";
/* Requested file didn't exist. */
static const char error_noexists[] =
"Requested file didn't exist.\n";
/* Sent file cannot be empty. */
static const char error_empty[] =
"Can't send an empty file!\n";
/* Not enough space left on the calculator. */
static const char error_nospace[] =
"Not enough space on the calculator for the file you're trying to send.\n"
"If you believe there should be, try optimizing (OPT) on the calculator\n"
"(in MEMORY menu) and try again.\n";
/* ************************************************************************** */
/* Auxiliary functions */
/* ************************************************************************** */
/* ---
* Auxiliary functions.
* --- */
/**
* sendfile_confirm:
* Confirm file sending.
@ -171,9 +182,11 @@ static void print_file_info(void *cookie, const char *dir, const char *name,
/* put the string */
puts(buf);
}
/* ************************************************************************** */
/* Main function */
/* ************************************************************************** */
/* ---
* Main function.
* --- */
/**
* main:
* User entry point of the program.
@ -189,17 +202,18 @@ int main(int ac, char **av)
casio_link_t *handle = NULL;
casio_fs_t *fs = NULL;
/* Parse args */
/* Decode the arguments. */
if (!parse_args(ac, av, &args))
return (0);
/* Initialize the link */
/* Initialize the link. */
if (args.com)
err = casio_open_com(&handle, args.initflags, args.com, args.use);
else
err = casio_open_usb(&handle, args.initflags);
if (err) {
/* display error */
switch (err) {
case casio_error_nocalc:
fprintf(stderr, error_noconnexion);
@ -212,7 +226,8 @@ int main(int ac, char **av)
break;
}
/* closing, removing if necessary */
/* Close and remove if necessary. */
if (args.menu == mn_send)
fclose(args.local);
if (args.menu == mn_get && args.local != stdout) {
@ -222,7 +237,8 @@ int main(int ac, char **av)
return (1);
}
/* Change speed, and things */
/* Change speed, and things. */
if (args.do_the_set) {
err = casio_setlink(handle, args.set);
if (err)
@ -230,6 +246,7 @@ int main(int ac, char **av)
}
/* Check according to menu */
switch (args.menu) {
#if 0
case mn_send:
@ -301,7 +318,8 @@ int main(int ac, char **av)
break;
}
/* put error */
/* Put the error. */
if (err && err != casio_error_noow)
goto fail;
@ -309,7 +327,8 @@ int main(int ac, char **av)
puts("\b\b\b\b\b\bTransfer complete.");
if (args.local && args.local != stdout) fclose(args.local);
/* terminate communication and de-initialize link handle */
/* Terminate communication and de-initialize link handle. */
casio_close_fs(fs);
casio_close_link(handle);
handle = NULL;