Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change port array in PROGRAMMER to be const char * #1699

Merged
merged 6 commits into from
Feb 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,8 @@ add_library(libavrdude
set_target_properties(libavrdude PROPERTIES
PREFIX ""
PUBLIC_HEADER "libavrdude.h;libavrdude-avrintel.h"
VERSION 1.0.0
SOVERSION 1
VERSION 2.0.0
SOVERSION 2
)

target_include_directories(libavrdude
Expand Down
2 changes: 1 addition & 1 deletion src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ libavrdude_a_SOURCES = \
xbee.h \
xbee.c
libavrdude_la_SOURCES = $(libavrdude_a_SOURCES)
libavrdude_la_LDFLAGS = -version-info 1:0
libavrdude_la_LDFLAGS = -version-info 2:0

include_HEADERS = libavrdude.h
include_HEADERS += libavrdude-avrintel.h
Expand Down
2 changes: 1 addition & 1 deletion src/arduino.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ static int arduino_read_sig_bytes(const PROGRAMMER *pgm, const AVRPART *p, const

static int arduino_open(PROGRAMMER *pgm, const char *port) {
union pinfo pinfo;
strcpy(pgm->port, port);
pgm->port = port;
pinfo.serialinfo.baud = pgm->baudrate? pgm->baudrate: 115200;
pinfo.serialinfo.cflags = SERIAL_8N1;
if (serial_open(port, pinfo, &pgm->fd)==-1) {
Expand Down
2 changes: 1 addition & 1 deletion src/avr910.c
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ static int avr910_open(PROGRAMMER *pgm, const char *port) {
pgm->baudrate = 19200;
}

strcpy(pgm->port, port);
pgm->port = port;
pinfo.serialinfo.baud = pgm->baudrate;
pinfo.serialinfo.cflags = SERIAL_8N1;
if (serial_open(port, pinfo, &pgm->fd)==-1) {
Expand Down
2 changes: 1 addition & 1 deletion src/buspirate.c
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ static int buspirate_open(PROGRAMMER *pgm, const char *port) {

pinfo.serialinfo.baud = pgm->baudrate;
pinfo.serialinfo.cflags = SERIAL_8N1;
strcpy(pgm->port, port);
pgm->port = port;
if (serial_open(port, pinfo, &pgm->fd)==-1) {
return -1;
}
Expand Down
2 changes: 1 addition & 1 deletion src/butterfly.c
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ static void butterfly_enable(PROGRAMMER *pgm, const AVRPART *p) {

static int butterfly_open(PROGRAMMER *pgm, const char *port) {
union pinfo pinfo;
strcpy(pgm->port, port);
pgm->port = port;
/*
* If baudrate was not specified use 19200 Baud
*/
Expand Down
5 changes: 2 additions & 3 deletions src/developer_opts.c
Original file line number Diff line number Diff line change
Expand Up @@ -1201,11 +1201,9 @@ static void dev_pgm_raw(const PROGRAMMER *pgm) {
if(dp.usbproduct && *dp.usbproduct)
dev_raw_dump(dp.usbproduct, strlen(dp.usbproduct)+1, id, "usbprod", 0);

// Zap all bytes beyond terminating nul of desc, type and port array
// Zap all bytes beyond terminating nul of type array
if((len = (int) strlen(dp.type)+1) < (int) sizeof dp.type)
memset(dp.type + len, 0, sizeof dp.type - len);
if((len = (int) strlen(dp.port)+1) < (int) sizeof dp.port)
memset(dp.port + len, 0, sizeof dp.port - len);

// Zap address values
dp.desc = NULL;
Expand All @@ -1219,6 +1217,7 @@ static void dev_pgm_raw(const PROGRAMMER *pgm) {
dp.usbvendor = NULL;
dp.usbproduct = NULL;
dp.hvupdi_support = NULL;
dp.port = NULL;

// Only dump contents of PROGRAMMER struct up to and excluding the fd component
dev_raw_dump((char *) &dp, offsetof(PROGRAMMER, fd), id, "pgm", 0);
Expand Down
2 changes: 1 addition & 1 deletion src/ft245r.c
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,7 @@ static int ft245r_open(PROGRAMMER *pgm, const char *port) {
return rv;
}

strcpy(pgm->port, port);
pgm->port = port;

// read device string cut after 8 chars (max. length of serial number)
if ((sscanf(port, "usb:%8s", device) != 1)) {
Expand Down
4 changes: 2 additions & 2 deletions src/jtag3.c
Original file line number Diff line number Diff line change
Expand Up @@ -1708,7 +1708,7 @@ int jtag3_open_common(PROGRAMMER *pgm, const char *port, int mode_switch) {
pgm->fd.usb.wep = USBDEV_BULK_EP_WRITE_3;
pgm->fd.usb.eep = 0;

strcpy(pgm->port, port);
pgm->port = port;
rv = serial_open(port, pinfo, &pgm->fd);
}
if (rv < 0) {
Expand All @@ -1723,7 +1723,7 @@ int jtag3_open_common(PROGRAMMER *pgm, const char *port, int mode_switch) {
pgm->fd.usb.wep = USBDEV_BULK_EP_WRITE_3;
pgm->fd.usb.eep = USBDEV_EVT_EP_READ_3;

strcpy(pgm->port, port);
pgm->port = port;
rv = serial_open(port, pinfo, &pgm->fd);
}
#endif /* HAVE_LIBUSB */
Expand Down
2 changes: 1 addition & 1 deletion src/jtagmkI.c
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ static int jtagmkI_open(PROGRAMMER *pgm, const char *port)

pmsg_notice2("jtagmkI_open()\n");

strcpy(pgm->port, port);
pgm->port = port;
PDATA(pgm)->initial_baudrate = -1L;

for (i = 0; i < sizeof(baudtab) / sizeof(baudtab[0]); i++) {
Expand Down
14 changes: 7 additions & 7 deletions src/jtagmkII.c
Original file line number Diff line number Diff line change
Expand Up @@ -1457,7 +1457,7 @@ static int jtagmkII_open(PROGRAMMER *pgm, const char *port) {
#endif
}

strcpy(pgm->port, port);
pgm->port = port;
if (serial_open(port, pinfo, &pgm->fd)==-1) {
return -1;
}
Expand Down Expand Up @@ -1509,7 +1509,7 @@ static int jtagmkII_open_dw(PROGRAMMER *pgm, const char *port) {
#endif
}

strcpy(pgm->port, port);
pgm->port = port;
if (serial_open(port, pinfo, &pgm->fd)==-1) {
return -1;
}
Expand Down Expand Up @@ -1561,7 +1561,7 @@ static int jtagmkII_open_pdi(PROGRAMMER *pgm, const char *port) {
#endif
}

strcpy(pgm->port, port);
pgm->port = port;
if (serial_open(port, pinfo, &pgm->fd)==-1) {
return -1;
}
Expand Down Expand Up @@ -1620,7 +1620,7 @@ static int jtagmkII_dragon_open(PROGRAMMER *pgm, const char *port) {
#endif
}

strcpy(pgm->port, port);
pgm->port = port;
if (serial_open(port, pinfo, &pgm->fd)==-1) {
return -1;
}
Expand Down Expand Up @@ -1673,7 +1673,7 @@ static int jtagmkII_dragon_open_dw(PROGRAMMER *pgm, const char *port) {
#endif
}

strcpy(pgm->port, port);
pgm->port = port;
if (serial_open(port, pinfo, &pgm->fd)==-1) {
return -1;
}
Expand Down Expand Up @@ -1726,7 +1726,7 @@ static int jtagmkII_dragon_open_pdi(PROGRAMMER *pgm, const char *port) {
#endif
}

strcpy(pgm->port, port);
pgm->port = port;
if (serial_open(port, pinfo, &pgm->fd)==-1) {
return -1;
}
Expand Down Expand Up @@ -3231,7 +3231,7 @@ static int jtagmkII_open32(PROGRAMMER *pgm, const char *port) {
#endif
}

strcpy(pgm->port, port);
pgm->port = port;
if (serial_open(port, pinfo, &pgm->fd)==-1) {
return -1;
}
Expand Down
16 changes: 14 additions & 2 deletions src/libavrdude.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,19 @@
#include "libavrdude-avrintel.h"
#undef LIBAVRDUDE_INCLUDE_INTERNAL_HEADERS

/*
* The libavrdude library contains useful functions for programming
* Microchip's 8-bit AVR microprocessors. The command line program avrdude
* was written using this library; its source code is a good example of how
* to use the library. Out of necessity libavrdude routinely changes
* PROGRAMMER, AVRPART and other structures to keep up with new programmers
* and with new parts and programming interfaces from Microchip. Any
* application that uses this library should ensure that it links to a
* libavrdude binary that is compatible with this header file, ideally the
* version that was shipped together with this header file or one that was
* compiled from source together with the application.
*/

typedef uint32_t pinmask_t;
/*
* Values returned by library functions.
Expand Down Expand Up @@ -872,7 +885,6 @@ typedef struct { // Memory cache for a subset of cached pages
#define OFF 0 // Many contexts: reset, power, LEDs, ...
#define ON 1 // Many contexts

#define PGM_PORTLEN PATH_MAX
#define PGM_TYPELEN 32

typedef enum {
Expand Down Expand Up @@ -951,7 +963,7 @@ typedef struct programmer_t {
// Values below are not set by config_gram.y; ensure fd is first for dev_pgm_raw()
union filedescriptor fd;
char type[PGM_TYPELEN];
char port[PGM_PORTLEN];
const char *port;
unsigned int pinno[N_PINS]; // TODO to be removed if old pin data no longer needed
exit_vcc_t exit_vcc; // Should these be set in avrdude.conf?
exit_reset_t exit_reset;
Expand Down
2 changes: 1 addition & 1 deletion src/linuxspi.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ static int linuxspi_open(PROGRAMMER *pgm, const char *pt) {
}
}

strcpy(pgm->port, port);
pgm->port = port;
fd_spidev = open(pgm->port, O_RDWR);
if (fd_spidev < 0) {
pmsg_ext_error("unable to open the spidev device %s: %s\n", pgm->port, strerror(errno));
Expand Down
4 changes: 3 additions & 1 deletion src/serialadapter.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,14 @@ static int sa_snmatch(const char *sn, const char *q) {
return sn && (str_starts(sn, q) || (str_starts(q , "...") && str_ends(sn, q+3)));
}

#define null_len(s) ((s)? strlen(s): 0)

// Order two SERPORTs port strings: base first then trailing numbers, if any
static int sa_portcmp(const void *p, const void *q) {
int ret;
const char *a = ((SERPORT *) p)->port, *b = ((SERPORT *) q)->port;
const char *na = str_endnumber(a), *nb = str_endnumber(b);
size_t la = strlen(a) - (na? strlen(na): 0), lb = strlen(b) - (nb? strlen(nb): 0);
size_t la = null_len(a) - null_len(na), lb = null_len(b) - null_len(nb);

// Compare string bases first
if(la && lb && (ret = strncasecmp(a, b, la < lb? la: lb)))
Expand Down
2 changes: 1 addition & 1 deletion src/serialupdi.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ static void serialupdi_teardown(PROGRAMMER * pgm)
}

static int serialupdi_open(PROGRAMMER *pgm, const char *port) {
strcpy(pgm->port, port);
pgm->port = port;
return updi_link_open(pgm);
}

Expand Down
2 changes: 1 addition & 1 deletion src/stk500.c
Original file line number Diff line number Diff line change
Expand Up @@ -864,7 +864,7 @@ static void stk500_enable(PROGRAMMER *pgm, const AVRPART *p) {

static int stk500_open(PROGRAMMER *pgm, const char *port) {
union pinfo pinfo;
strcpy(pgm->port, port);
pgm->port = port;
pinfo.serialinfo.baud = pgm->baudrate? pgm->baudrate: 115200;
pinfo.serialinfo.cflags = SERIAL_8N1;
if (serial_open(port, pinfo, &pgm->fd)==-1) {
Expand Down
10 changes: 5 additions & 5 deletions src/stk500v2.c
Original file line number Diff line number Diff line change
Expand Up @@ -2207,7 +2207,7 @@ static int stk500v2_open(PROGRAMMER *pgm, const char *port) {
#endif
}

strcpy(pgm->port, port);
pgm->port = port;
if (serial_open(port, pinfo, &pgm->fd)==-1) {
return -1;
}
Expand Down Expand Up @@ -2270,7 +2270,7 @@ static int stk600_open(PROGRAMMER *pgm, const char *port) {
#endif
}

strcpy(pgm->port, port);
pgm->port = port;
if (serial_open(port, pinfo, &pgm->fd)==-1) {
return -1;
}
Expand Down Expand Up @@ -4049,7 +4049,7 @@ static int stk500v2_jtagmkII_open(PROGRAMMER *pgm, const char *port) {
#endif
}

strcpy(pgm->port, port);
pgm->port = port;
if (serial_open(port, pinfo, &pgm->fd)==-1) {
return -1;
}
Expand Down Expand Up @@ -4159,7 +4159,7 @@ static int stk500v2_dragon_isp_open(PROGRAMMER *pgm, const char *port) {
#endif
}

strcpy(pgm->port, port);
pgm->port = port;
if (serial_open(port, pinfo, &pgm->fd)==-1) {
return -1;
}
Expand Down Expand Up @@ -4235,7 +4235,7 @@ static int stk500v2_dragon_hv_open(PROGRAMMER *pgm, const char *port) {
#endif
}

strcpy(pgm->port, port);
pgm->port = port;
if (serial_open(port, pinfo, &pgm->fd)==-1) {
return -1;
}
Expand Down
3 changes: 3 additions & 0 deletions src/strutil.c
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,9 @@ char *str_utoa(unsigned n, char *buf, int base) {
char *str_endnumber(const char *str) {
const char *ret = NULL;

if(!str)
return NULL;

for(const char *end = str + strlen(str)-1; end >= str; end--)
if(isdigit((unsigned char) *end))
ret = end;
Expand Down
2 changes: 1 addition & 1 deletion src/urclock.c
Original file line number Diff line number Diff line change
Expand Up @@ -2228,7 +2228,7 @@ static void urclock_disable(const PROGRAMMER *pgm) {
static int urclock_open(PROGRAMMER *pgm, const char *port) {
union pinfo pinfo;

strcpy(pgm->port, port);
pgm->port = port;
pinfo.serialinfo.baud = pgm->baudrate? pgm->baudrate: 115200;
pinfo.serialinfo.cflags = SERIAL_8N1;
if(serial_open(port, pinfo, &pgm->fd) == -1)
Expand Down
2 changes: 1 addition & 1 deletion src/wiring.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ static int wiring_open(PROGRAMMER *pgm, const char *port) {
int timetosnooze;
union pinfo pinfo;

strcpy(pgm->port, port);
pgm->port = port;
pinfo.serialinfo.baud = pgm->baudrate ? pgm->baudrate: 115200;
pinfo.serialinfo.cflags = SERIAL_8N1;
serial_open(port, pinfo, &pgm->fd);
Expand Down
2 changes: 1 addition & 1 deletion src/xbee.c
Original file line number Diff line number Diff line change
Expand Up @@ -1555,7 +1555,7 @@ static int xbee_getsync(const PROGRAMMER *pgm) {

static int xbee_open(PROGRAMMER *pgm, const char *port) {
union pinfo pinfo;
strcpy(pgm->port, port);
pgm->port = port;
pinfo.serialinfo.baud = pgm->baudrate;
pinfo.serialinfo.cflags = SERIAL_8N1;

Expand Down
Loading