Browse Source

Consistently use snprintf instead of sprintf

There was a last instance of sprintf which somehow was not converted.
I know it can't fail, but for consistency, let's use snprintf and
check for truncation as we already do in gather_i2c_busses().

Signed-off-by: Jean Delvare <jdelvare@suse.de>
tags/v4.2
Jean Delvare 7 years ago
parent
commit
955b13bf47
  1. 1
      CHANGES
  2. 15
      tools/i2cbusses.c

1
CHANGES

@ -2,6 +2,7 @@ i2c-tools CHANGES
-----------------
master
tools: Consistently use snprintf instead of sprintf
decode-dimms: Print SPD revision for DDR3 too
Move SDR-specific code

15
tools/i2cbusses.c

@ -406,14 +406,21 @@ int parse_i2c_address(const char *address_arg, int all_addrs)
int open_i2c_dev(int i2cbus, char *filename, size_t size, int quiet)
{
int file;
int file, len;
snprintf(filename, size, "/dev/i2c/%d", i2cbus);
filename[size - 1] = '\0';
len = snprintf(filename, size, "/dev/i2c/%d", i2cbus);
if (len >= (int)size) {
fprintf(stderr, "%s: path truncated\n", filename);
return -EOVERFLOW;
}
file = open(filename, O_RDWR);
if (file < 0 && (errno == ENOENT || errno == ENOTDIR)) {
sprintf(filename, "/dev/i2c-%d", i2cbus);
len = snprintf(filename, size, "/dev/i2c-%d", i2cbus);
if (len >= (int)size) {
fprintf(stderr, "%s: path truncated\n", filename);
return -EOVERFLOW;
}
file = open(filename, O_RDWR);
}

Loading…
Cancel
Save