mirror of
https://github.com/avrdudes/avrdude.git
synced 2026-09-28 03:56:26 +03:00
Use pins_to_strdup() instead of pins_to_str()
The latter returns a string in a static buffer that is overwritten by the next call. Unfortunately, this function was used more than once in arguments of the *same* msg_error(), which would have given a wrong error message. pins_to_strdup() returns a string to malloc'd space that needs freeing.
This commit is contained in:
@@ -601,21 +601,26 @@ static int avrftdi_pin_setup(const PROGRAMMER *pgm) {
|
||||
avrftdi_check_pins_bb(pgm, true);
|
||||
imsg_error("pin configuration for FTDI MPSSE must be:\n");
|
||||
if (pgm->flag == PGM_FL_IS_JTAG) {
|
||||
imsg_error("%s: 0, %s: 1, %s: 2, %s :3 (is: %s, %s, %s, %s)\n",
|
||||
char *ptck = pins_to_strdup(&pgm->pin[PIN_JTAG_TCK]),
|
||||
*ptdi = pins_to_strdup(&pgm->pin[PIN_JTAG_TDI]),
|
||||
*ptdo = pins_to_strdup(&pgm->pin[PIN_JTAG_TDO]),
|
||||
*ptms = pins_to_strdup(&pgm->pin[PIN_JTAG_TMS]);
|
||||
imsg_error("%s: 0; %s: 1; %s: 2; %s: 3 (is: %s; %s; %s; %s)\n",
|
||||
avr_pin_name(PIN_JTAG_TCK), avr_pin_name(PIN_JTAG_TDI),
|
||||
avr_pin_name(PIN_JTAG_TDO), avr_pin_name(PIN_JTAG_TMS),
|
||||
pins_to_str(&pgm->pin[PIN_JTAG_TCK]),
|
||||
pins_to_str(&pgm->pin[PIN_JTAG_TDI]),
|
||||
pins_to_str(&pgm->pin[PIN_JTAG_TDO]),
|
||||
pins_to_str(&pgm->pin[PIN_JTAG_TMS]));
|
||||
*ptck? ptck: "?", *ptdi? ptdi: "?",
|
||||
*ptdo? ptdo: "?", *ptms? ptms: "?");
|
||||
free(ptck); free(ptdi); free(ptdo); free(ptms);
|
||||
} else {
|
||||
imsg_error("%s: 0, %s: 1, %s: 2 (is: %s, %s, %s)\n",
|
||||
avr_pin_name(PIN_AVR_SCK),
|
||||
avr_pin_name(PIN_AVR_SDO),
|
||||
char *psck = pins_to_strdup(&pgm->pin[PIN_AVR_SCK]),
|
||||
*psdo = pins_to_strdup(&pgm->pin[PIN_AVR_SDO]),
|
||||
*psdi = pins_to_strdup(&pgm->pin[PIN_AVR_SDI]);
|
||||
imsg_error("%s: 0; %s: 1; %s: 2 (is: %s; %s; %s)\n",
|
||||
avr_pin_name(PIN_AVR_SCK), avr_pin_name(PIN_AVR_SDO),
|
||||
avr_pin_name(PIN_AVR_SDI),
|
||||
pins_to_str(&pgm->pin[PIN_AVR_SCK]),
|
||||
pins_to_str(&pgm->pin[PIN_AVR_SDO]),
|
||||
pins_to_str(&pgm->pin[PIN_AVR_SDI]));
|
||||
*psck? psck: "?", *psdo? psdo: "?",
|
||||
*psdi? psdi: "?");
|
||||
free(psck); free(psdo); free(psdi);
|
||||
}
|
||||
imsg_error("if other pin configuration is used, fallback to slower bitbanging mode is used\n");
|
||||
|
||||
|
||||
34
src/pgm.c
34
src/pgm.c
@@ -287,34 +287,12 @@ void programmer_display(PROGRAMMER *pgm, const char * p) {
|
||||
|
||||
|
||||
void pgm_display_generic_mask(const PROGRAMMER *pgm, const char *p, unsigned int show) {
|
||||
if(show & (1<<PPI_AVR_VCC))
|
||||
msg_info("%s VCC = %s\n", p, pins_to_str(&pgm->pin[PPI_AVR_VCC]));
|
||||
if(show & (1<<PPI_AVR_BUFF))
|
||||
msg_info("%s BUFF = %s\n", p, pins_to_str(&pgm->pin[PPI_AVR_BUFF]));
|
||||
if(show & (1<<PIN_AVR_RESET))
|
||||
msg_info("%s RESET = %s\n", p, pins_to_str(&pgm->pin[PIN_AVR_RESET]));
|
||||
if(show & (1<<PIN_AVR_SCK))
|
||||
msg_info("%s SCK = %s\n", p, pins_to_str(&pgm->pin[PIN_AVR_SCK]));
|
||||
if(show & (1<<PIN_AVR_SDO))
|
||||
msg_info("%s SDO = %s\n", p, pins_to_str(&pgm->pin[PIN_AVR_SDO]));
|
||||
if(show & (1<<PIN_AVR_SDI))
|
||||
msg_info("%s SDI = %s\n", p, pins_to_str(&pgm->pin[PIN_AVR_SDI]));
|
||||
if(show & (1<<PIN_JTAG_TCK))
|
||||
msg_info("%s TCK = %s\n", p, pins_to_str(&pgm->pin[PIN_JTAG_TCK]));
|
||||
if(show & (1<<PIN_JTAG_TDI))
|
||||
msg_info("%s TDI = %s\n", p, pins_to_str(&pgm->pin[PIN_JTAG_TDI]));
|
||||
if(show & (1<<PIN_JTAG_TDO))
|
||||
msg_info("%s TDO = %s\n", p, pins_to_str(&pgm->pin[PIN_JTAG_TDO]));
|
||||
if(show & (1<<PIN_JTAG_TMS))
|
||||
msg_info("%s TMS = %s\n", p, pins_to_str(&pgm->pin[PIN_JTAG_TMS]));
|
||||
if(show & (1<<PIN_LED_ERR))
|
||||
msg_info("%s ERR LED = %s\n", p, pins_to_str(&pgm->pin[PIN_LED_ERR]));
|
||||
if(show & (1<<PIN_LED_RDY))
|
||||
msg_info("%s RDY LED = %s\n", p, pins_to_str(&pgm->pin[PIN_LED_RDY]));
|
||||
if(show & (1<<PIN_LED_PGM))
|
||||
msg_info("%s PGM LED = %s\n", p, pins_to_str(&pgm->pin[PIN_LED_PGM]));
|
||||
if(show & (1<<PIN_LED_VFY))
|
||||
msg_info("%s VFY LED = %s\n", p, pins_to_str(&pgm->pin[PIN_LED_VFY]));
|
||||
for(int pbit = 1; pbit < N_PINS; pbit++)
|
||||
if(show & (1<<pbit)) {
|
||||
char *pinstr = pins_to_strdup(pgm->pin + pbit);
|
||||
msg_info("%s %-6s = %s\n", p, avr_pin_name(pbit), *pinstr? pinstr: "(not used)");
|
||||
free(pinstr);
|
||||
}
|
||||
}
|
||||
|
||||
void pgm_display_generic(const PROGRAMMER *pgm, const char *p) {
|
||||
|
||||
Reference in New Issue
Block a user