Merge pull request #1042 from dl8dtl/fix_1041

Handle invalid -U file format specifiers for input
This commit is contained in:
Stefan Rueger 2022-08-04 18:11:21 +01:00 committed by GitHub
commit bdfeb0ad34
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 0 deletions

View File

@ -736,14 +736,17 @@ fuse bit settings.
hexadecimal; each value will get the string hexadecimal; each value will get the string
.Em 0x .Em 0x
prepended. prepended.
Only valid on output.
.It Ar o .It Ar o
octal; each value will get a octal; each value will get a
.Em 0 .Em 0
prepended unless it is less than 8 in which case it gets no prefix. prepended unless it is less than 8 in which case it gets no prefix.
Only valid on output.
.It Ar b .It Ar b
binary; each value will get the string binary; each value will get the string
.Em 0b .Em 0b
prepended. prepended.
Only valid on output.
.El .El
.Pp .Pp
The default is to use auto detection for input files, and raw binary The default is to use auto detection for input files, and raw binary

View File

@ -809,13 +809,16 @@ fuse bit settings.
@item h @item h
hexadecimal; each value will get the string @emph{0x} prepended. hexadecimal; each value will get the string @emph{0x} prepended.
Only valid on output.
@item o @item o
octal; each value will get a @emph{0} octal; each value will get a @emph{0}
prepended unless it is less than 8 in which case it gets no prefix. prepended unless it is less than 8 in which case it gets no prefix.
Only valid on output.
@item b @item b
binary; each value will get the string @emph{0b} prepended. binary; each value will get the string @emph{0b} prepended.
Only valid on output.
@end table @end table

View File

@ -1157,6 +1157,13 @@ static int fileio_imm(struct fioparms * fio,
rc = loc; rc = loc;
} }
break; break;
case FIO_WRITE:
avrdude_message(MSG_INFO,
"%s: Invalid file format 'immediate' for output\n",
progname);
return -1;
default: default:
avrdude_message(MSG_INFO, "%s: fileio: invalid operation=%d\n", avrdude_message(MSG_INFO, "%s: fileio: invalid operation=%d\n",
progname, fio->op); progname, fio->op);
@ -1271,27 +1278,32 @@ static int fileio_num(struct fioparms * fio,
FILEFMT fmt) FILEFMT fmt)
{ {
const char *prefix; const char *prefix;
const char *name;
char cbuf[20]; char cbuf[20];
int base, i, num; int base, i, num;
switch (fmt) { switch (fmt) {
case FMT_HEX: case FMT_HEX:
name = "hex";
prefix = "0x"; prefix = "0x";
base = 16; base = 16;
break; break;
default: default:
case FMT_DEC: case FMT_DEC:
name = "decimal";
prefix = ""; prefix = "";
base = 10; base = 10;
break; break;
case FMT_OCT: case FMT_OCT:
name = "octal";
prefix = "0"; prefix = "0";
base = 8; base = 8;
break; break;
case FMT_BIN: case FMT_BIN:
name = "binary";
prefix = "0b"; prefix = "0b";
base = 2; base = 2;
break; break;
@ -1301,6 +1313,13 @@ static int fileio_num(struct fioparms * fio,
switch (fio->op) { switch (fio->op) {
case FIO_WRITE: case FIO_WRITE:
break; break;
case FIO_READ:
avrdude_message(MSG_INFO,
"%s: Invalid file format '%s' for input\n",
progname, name);
return -1;
default: default:
avrdude_message(MSG_INFO, "%s: fileio: invalid operation=%d\n", avrdude_message(MSG_INFO, "%s: fileio: invalid operation=%d\n",
progname, fio->op); progname, fio->op);

View File

@ -354,6 +354,7 @@ int do_op(PROGRAMMER * pgm, struct avrpart * p, UPDATE * upd, enum updateflags f
progname, mem->desc, alias_mem_desc); progname, mem->desc, alias_mem_desc);
report_progress(0, 1, "Reading"); report_progress(0, 1, "Reading");
rc = avr_read(pgm, p, upd->memtype, 0); rc = avr_read(pgm, p, upd->memtype, 0);
report_progress(1, 1, NULL); report_progress(1, 1, NULL);
if (rc < 0) { if (rc < 0) {