Move the error handling for invalid file formats to fileio.c
The checks used to be in update.c, but as they are related to the intended file operation, they are better placed in fileio.c. The checks affected are to refuse 'm' on output (file write), and 'd', 'h', 'o', and 'b' formats on input (file read).
This commit is contained in:
parent
ce1ae41dd6
commit
cc93bd2c83
19
src/fileio.c
19
src/fileio.c
|
@ -1135,6 +1135,13 @@ static int fileio_imm(struct fioparms * fio,
|
|||
rc = loc;
|
||||
}
|
||||
break;
|
||||
|
||||
case FIO_WRITE:
|
||||
avrdude_message(MSG_INFO,
|
||||
"%s: Invalid file format 'immediate' for output\n",
|
||||
progname);
|
||||
return -1;
|
||||
|
||||
default:
|
||||
avrdude_message(MSG_INFO, "%s: fileio: invalid operation=%d\n",
|
||||
progname, fio->op);
|
||||
|
@ -1248,27 +1255,32 @@ static int fileio_num(struct fioparms * fio,
|
|||
FILEFMT fmt)
|
||||
{
|
||||
const char *prefix;
|
||||
const char *name;
|
||||
char cbuf[20];
|
||||
int base, i, num;
|
||||
|
||||
switch (fmt) {
|
||||
case FMT_HEX:
|
||||
name = "hex";
|
||||
prefix = "0x";
|
||||
base = 16;
|
||||
break;
|
||||
|
||||
default:
|
||||
case FMT_DEC:
|
||||
name = "decimal";
|
||||
prefix = "";
|
||||
base = 10;
|
||||
break;
|
||||
|
||||
case FMT_OCT:
|
||||
name = "octal";
|
||||
prefix = "0";
|
||||
base = 8;
|
||||
break;
|
||||
|
||||
case FMT_BIN:
|
||||
name = "binary";
|
||||
prefix = "0b";
|
||||
base = 2;
|
||||
break;
|
||||
|
@ -1278,6 +1290,13 @@ static int fileio_num(struct fioparms * fio,
|
|||
switch (fio->op) {
|
||||
case FIO_WRITE:
|
||||
break;
|
||||
|
||||
case FIO_READ:
|
||||
avrdude_message(MSG_INFO,
|
||||
"%s: Invalid file format '%s' for input\n",
|
||||
progname, name);
|
||||
return -1;
|
||||
|
||||
default:
|
||||
avrdude_message(MSG_INFO, "%s: fileio: invalid operation=%d\n",
|
||||
progname, fio->op);
|
||||
|
|
34
src/update.c
34
src/update.c
|
@ -238,12 +238,6 @@ int do_op(PROGRAMMER * pgm, struct avrpart * p, UPDATE * upd, enum updateflags f
|
|||
/*
|
||||
* read out the specified device memory and write it to a file
|
||||
*/
|
||||
if (upd->format == FMT_IMM) {
|
||||
avrdude_message(MSG_INFO,
|
||||
"%s: Invalid file format 'immediate' for output\n",
|
||||
progname, upd->filename);
|
||||
return -1;
|
||||
}
|
||||
if (quell_progress < 2) {
|
||||
avrdude_message(MSG_INFO, "%s: reading %s%s memory:\n",
|
||||
progname, mem->desc, alias_mem_desc);
|
||||
|
@ -278,34 +272,6 @@ int do_op(PROGRAMMER * pgm, struct avrpart * p, UPDATE * upd, enum updateflags f
|
|||
* write the selected device memory using data from a file; first
|
||||
* read the data from the specified file
|
||||
*/
|
||||
const char *name = 0;
|
||||
switch (upd->format) {
|
||||
case FMT_HEX:
|
||||
name = "hex";
|
||||
break;
|
||||
|
||||
case FMT_DEC:
|
||||
name = "decimal";
|
||||
break;
|
||||
|
||||
case FMT_OCT:
|
||||
name = "octal";
|
||||
break;
|
||||
|
||||
case FMT_BIN:
|
||||
name = "binary";
|
||||
break;
|
||||
|
||||
default:
|
||||
// no action needed
|
||||
break;
|
||||
}
|
||||
if (name != 0) {
|
||||
avrdude_message(MSG_INFO,
|
||||
"%s: Invalid file format '%s' for input\n",
|
||||
progname, name, upd->filename);
|
||||
return -1;
|
||||
}
|
||||
if (quell_progress < 2) {
|
||||
avrdude_message(MSG_INFO, "%s: reading input file \"%s\"\n",
|
||||
progname,
|
||||
|
|
Loading…
Reference in New Issue