@@ -138,7 +138,6 @@ static int nexttok(char * buf, char ** tok, char ** next)
138138
139139 if (* n ) {
140140 * n = 0 ;
141- avrdude_message (MSG_INFO , "q: %s\n" , q );
142141 n ++ ;
143142 }
144143
@@ -462,13 +461,17 @@ static int cmd_write(PROGRAMMER * pgm, struct avrpart * p,
462461 if (argv [i ][0 ] == '\'' && argv [i ][2 ] == '\'' ) {
463462 data .ll = argv [i ][1 ];
464463 } else {
465- // Try string that starts and ends with quote
464+ // Try string that starts and ends with quotes
466465 if (argv [i ][0 ] == '\"' && argv [i ][strlen (argv [i ]) - 1 ] == '\"' ) {
467- data .str_ptr = calloc (strlen (argv [i ])+ 0x10 , sizeof (char ));
466+ data .str_ptr = calloc (strlen (argv [i ]), sizeof (char ));
467+ if (data .str_ptr == NULL ) {
468+ avrdude_message (MSG_INFO , "%s (write str): out of memory\n" , progname );
469+ return -1 ;
470+ }
471+ // Strip start and end quotes
468472 strncpy (data .str_ptr , argv [i ] + 1 , strlen (argv [i ]) - 2 );
469- avrdude_message (MSG_INFO , "argv: %s, malloc: %s\n" , argv [i ], data .str_ptr );
470473 } else {
471- avrdude_message (MSG_INFO , "\n%s (write): can't parse data \"%s\" \n" ,
474+ avrdude_message (MSG_INFO , "\n%s (write): can't parse data '%s' \n" ,
472475 progname , argv [i ]);
473476 free (buf );
474477 return -1 ;
@@ -507,7 +510,7 @@ static int cmd_write(PROGRAMMER * pgm, struct avrpart * p,
507510 data .size = 1 ;
508511 }
509512 }
510- if (data .str_ptr != NULL ) {
513+ if (data .str_ptr ) {
511514 for (int16_t j = 0 ; j < strlen (data .str_ptr ); j ++ )
512515 buf [i - start_offset + data .bytes_grown ++ ] = (uint8_t )data .str_ptr [j ];
513516 free (data .str_ptr );
0 commit comments