Merge branch 'minor-fixes' of git://github.com/kerolasa/lelux-utiliteetit

* 'minor-fixes' of git://github.com/kerolasa/lelux-utiliteetit:
  lscpu: avoid double free
  libsmartcols: avoid variable dereference after release
  libfdisk: do not do the same thing twice in single if statement
  whereis: avoid printing uninitialized string
  setpriv: avoid alloca() use xmalloc() instead
  dmesg: avoid unnecessary variable assignment
  fdisk: avoid code duplication
  mkfs.cramfs: use defined failure name rather than magic value
  fdformat: match variable and print format types
  cfdisk: add braces to ensure operation order
  lscpu: avoid use of bzero() in favor of memset()
  setterm: remove unnecessary variable
  cal: remove unnused structure and definition
  textual: fix some typos
This commit is contained in:
Karel Zak 2014-07-14 16:03:48 +02:00
commit 2fa32bea49
19 changed files with 26 additions and 33 deletions

View File

@ -636,7 +636,7 @@ static void resize_on_signal(int dummy __attribute__((__unused__)))
static void menu_refresh_size(struct cfdisk *cf) static void menu_refresh_size(struct cfdisk *cf)
{ {
if (cf->menu && cf->menu->nitems) if (cf->menu && cf->menu->nitems)
cf->menu->page_sz = cf->menu->nitems / (LINES - 4) ? LINES - 4 : 0; cf->menu->page_sz = (cf->menu->nitems / (LINES - 4)) ? LINES - 4 : 0;
} }
static void menu_update_ignore(struct cfdisk *cf) static void menu_update_ignore(struct cfdisk *cf)

View File

@ -35,7 +35,7 @@ static void format_disk(int ctrl)
if (ioctl(ctrl, FDFMTTRK, (long) &descr) < 0) if (ioctl(ctrl, FDFMTTRK, (long) &descr) < 0)
err(EXIT_FAILURE, "ioctl: FDFMTTRK"); err(EXIT_FAILURE, "ioctl: FDFMTTRK");
printf("%3d\b\b\b", track); printf("%3ud\b\b\b", track);
fflush(stdout); fflush(stdout);
if (param.head == 2) { if (param.head == 2) {
descr.head = 1; descr.head = 1;
@ -63,7 +63,7 @@ static void verify_disk(char *name)
for (cyl = 0; cyl < param.track; cyl++) { for (cyl = 0; cyl < param.track; cyl++) {
int read_bytes; int read_bytes;
printf("%3d\b\b\b", cyl); printf("%u3d\b\b\b", cyl);
fflush(stdout); fflush(stdout);
read_bytes = read(fd, data, cyl_size); read_bytes = read(fd, data, cyl_size);
if (read_bytes != cyl_size) { if (read_bytes != cyl_size) {

View File

@ -725,16 +725,15 @@ static void print_all_devices_pt(struct fdisk_context *cxt)
static sector_t get_dev_blocks(char *dev) static sector_t get_dev_blocks(char *dev)
{ {
int fd; int fd, ret;
sector_t size; sector_t size;
if ((fd = open(dev, O_RDONLY)) < 0) if ((fd = open(dev, O_RDONLY)) < 0)
err(EXIT_FAILURE, _("cannot open %s"), dev); err(EXIT_FAILURE, _("cannot open %s"), dev);
if (blkdev_get_sectors(fd, &size) == -1) { ret = blkdev_get_sectors(fd, &size);
close(fd);
err(EXIT_FAILURE, _("BLKGETSIZE ioctl failed on %s"), dev);
}
close(fd); close(fd);
if (ret < 0)
err(EXIT_FAILURE, _("BLKGETSIZE ioctl failed on %s"), dev);
return size/2; return size/2;
} }

View File

@ -167,11 +167,9 @@ do_mmap(char *path, unsigned int size, unsigned int mode){
} }
start = mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0); start = mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0);
if (-1 == (int) (long) start) {
close(fd);
err(MKFS_EX_ERROR, "mmap");
}
close(fd); close(fd);
if (start == MAP_FAILED)
err(MKFS_EX_ERROR, "mmap");
return start; return start;
err: err:
free(start); free(start);

View File

@ -47,7 +47,7 @@ static int do_scale_by_power (uintmax_t *x, int base, int power)
* The optinal 'power' variable returns number associated with used suffix * The optinal 'power' variable returns number associated with used suffix
* {K,M,G,T,P,E,Z,Y} = {1,2,3,4,5,6,7,8}. * {K,M,G,T,P,E,Z,Y} = {1,2,3,4,5,6,7,8}.
* *
* The funtion also supports decimal point, for example: * The function also supports decimal point, for example:
* 0.5MB = 500000 * 0.5MB = 500000
* 0.5MiB = 512000 * 0.5MiB = 512000
* *

View File

@ -1739,7 +1739,7 @@ static int cmp_ebr_offsets(const void *a, const void *b)
struct pte *ae = (struct pte *) a, struct pte *ae = (struct pte *) a,
*be = (struct pte *) b; *be = (struct pte *) b;
if (ae->offset == 0 && ae->offset == 0) if (ae->offset == 0 && be->offset == 0)
return 0; return 0;
if (ae->offset == 0) if (ae->offset == 0)
return 1; return 1;

View File

@ -303,7 +303,7 @@ int fdisk_partition_next_partno(
* *
* Returns info about partition converted to printable string. * Returns info about partition converted to printable string.
* *
* For exmaple * For example
* *
* struct fdisk_parition *pa; * struct fdisk_parition *pa;
* *

View File

@ -390,7 +390,7 @@ int mnt_table_append_trailing_comment(struct libmnt_table *tb, const char *comm)
* same cache between more threads -- currently the cache does not provide any * same cache between more threads -- currently the cache does not provide any
* locking method. * locking method.
* *
* This function increments cache refrence counter. It's recomented to use * This function increments cache reference counter. It's recomented to use
* mnt_unref_cache() after mnt_table_set_cache() if you want to keep the cache * mnt_unref_cache() after mnt_table_set_cache() if you want to keep the cache
* referenced by @tb only. * referenced by @tb only.
* *

View File

@ -199,9 +199,9 @@ int scols_line_remove_child(struct libscols_line *ln, struct libscols_line *chil
DBG(LINE, ul_debugobj(ln, "remove child %p", child)); DBG(LINE, ul_debugobj(ln, "remove child %p", child));
list_del_init(&child->ln_children); list_del_init(&child->ln_children);
child->parent = NULL;
scols_unref_line(child); scols_unref_line(child);
child->parent = NULL;
scols_unref_line(ln); scols_unref_line(ln);
return 0; return 0;
} }

View File

@ -11,7 +11,7 @@
* @title: Version functions * @title: Version functions
* @short_description: functions to get the library version. * @short_description: functions to get the library version.
* *
* Note that library version is not the same thing as SONAME verison. The * Note that library version is not the same thing as SONAME version. The
* libsmarcols uses symbols versioning and SONAME is not modified for releases. * libsmarcols uses symbols versioning and SONAME is not modified for releases.
* *
* The library version and symbols version follow util-linux package versioning. * The library version and symbols version follow util-linux package versioning.

View File

@ -401,7 +401,7 @@ static int list(const struct last_control *ctl, struct utmp *p, time_t t, int wh
utline[4] = 0; utline[4] = 0;
/* /*
* Is this something we wanna show? * Is this something we want to show?
*/ */
if (ctl->show) { if (ctl->show) {
char **walk; char **walk;

View File

@ -187,12 +187,7 @@ enum {
#define TODAY_FLAG 0x400 /* flag day for highlighting */ #define TODAY_FLAG 0x400 /* flag day for highlighting */
#define FMT_ST_LINES 9
#define FMT_ST_CHARS 300 /* 90 suffices in most locales */ #define FMT_ST_CHARS 300 /* 90 suffices in most locales */
struct fmt_st
{
char s[FMT_ST_LINES][FMT_ST_CHARS];
};
static const int days_in_month[2][13] = { static const int days_in_month[2][13] = {
{0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}, {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},

View File

@ -408,13 +408,12 @@ static void lookup(const char *pattern, struct wh_dirlist *ls, int want)
int count = 0; int count = 0;
char *wait = NULL, *p; char *wait = NULL, *p;
DBG(printf("lookup dirs for '%s' (%s)", patbuf, pattern));
/* canonicalize pattern -- remove path suffix etc. */ /* canonicalize pattern -- remove path suffix etc. */
p = strrchr(pattern, '/'); p = strrchr(pattern, '/');
p = p ? p + 1 : (char *) pattern; p = p ? p + 1 : (char *) pattern;
strncpy(patbuf, p, PATH_MAX); strncpy(patbuf, p, PATH_MAX);
patbuf[PATH_MAX - 1] = '\0'; patbuf[PATH_MAX - 1] = '\0';
DBG(printf("lookup dirs for '%s' (%s)", patbuf, pattern));
p = strrchr(patbuf, '.'); p = strrchr(patbuf, '.');
if (p) if (p)
*p = '\0'; *p = '\0';

View File

@ -612,7 +612,7 @@ static void safe_fwrite(const char *buf, size_t size, FILE *out)
for (i = 0; i < size; i++) { for (i = 0; i < size; i++) {
const char *p = buf + i; const char *p = buf + i;
int rc, hex = 0; int rc, hex = 0;
size_t len = 1; size_t len;
#ifdef HAVE_WIDECHAR #ifdef HAVE_WIDECHAR
wchar_t wc; wchar_t wc;
@ -629,6 +629,7 @@ static void safe_fwrite(const char *buf, size_t size, FILE *out)
} }
i += len - 1; i += len - 1;
#else #else
len = 1;
if (!isprint((unsigned int) *p) && if (!isprint((unsigned int) *p) &&
!isspace((unsigned int) *p)) /* non-printable */ !isspace((unsigned int) *p)) /* non-printable */
hex = 1; hex = 1;

View File

@ -118,7 +118,7 @@ static int has_discard(const char *devname, struct sysfs_cxt *wholedisk)
* This is tricky to read the info from sys/, because the queue * This is tricky to read the info from sys/, because the queue
* atrributes are provided for whole devices (disk) only. We're trying * atrributes are provided for whole devices (disk) only. We're trying
* to reuse the whole-disk sysfs context to optimize this stuff (as * to reuse the whole-disk sysfs context to optimize this stuff (as
* system usualy have just one disk only). * system usually have just one disk only).
*/ */
if (sysfs_devno_to_wholedisk(dev, NULL, 0, &disk) || !disk) if (sysfs_devno_to_wholedisk(dev, NULL, 0, &disk) || !disk)
return 1; return 1;

View File

@ -258,7 +258,7 @@ int read_hypervisor_dmi(void)
if (rc) if (rc)
goto done; goto done;
free(buf); free(buf);
buf = NULL;
memory_scan: memory_scan:
#if defined(__x86_64__) || defined(__i386__) #if defined(__x86_64__) || defined(__i386__)
/* Fallback to memory scan (x86, x86_64) */ /* Fallback to memory scan (x86, x86_64) */

View File

@ -690,7 +690,7 @@ is_vmware_platform(void)
if (sigsetjmp(segv_handler_env, 1)) if (sigsetjmp(segv_handler_env, 1))
return 0; return 0;
bzero(&act, sizeof(act)); memset(&act, 0, sizeof(act));
act.sa_sigaction = segv_handler; act.sa_sigaction = segv_handler;
act.sa_flags = SA_SIGINFO; act.sa_flags = SA_SIGINFO;

View File

@ -254,9 +254,10 @@ static void dump_groups(void)
return; return;
} }
groups = alloca(n * sizeof(gid_t)); groups = xmalloc(n * sizeof(gid_t));
n = getgroups(n, groups); n = getgroups(n, groups);
if (n < 0) { if (n < 0) {
free(groups);
warn("getgroups failed"); warn("getgroups failed");
return; return;
} }
@ -273,6 +274,7 @@ static void dump_groups(void)
} }
} }
printf("\n"); printf("\n");
free(groups);
} }
static void dump(int dumplevel) static void dump(int dumplevel)

View File

@ -770,12 +770,11 @@ static void screendump(struct setterm_control *ctl)
size_t i, j; size_t i, j;
ssize_t rc; ssize_t rc;
char *inbuf, *outbuf, *p, *q; char *inbuf, *outbuf, *p, *q;
char dump_default[] = "screen.dump";
/* open source and destination files */ /* open source and destination files */
fd = open_snapshot_device(ctl); fd = open_snapshot_device(ctl);
if (!ctl->opt_sn_name) if (!ctl->opt_sn_name)
ctl->opt_sn_name = dump_default; ctl->opt_sn_name = "screen.dump";
out = fopen(ctl->opt_sn_name, ctl->opt_snap ? "w" : "a"); out = fopen(ctl->opt_sn_name, ctl->opt_snap ? "w" : "a");
if (!out) if (!out)
err(EXIT_DUMPFILE, _("can not open dump file %s for output"), ctl->opt_sn_name); err(EXIT_DUMPFILE, _("can not open dump file %s for output"), ctl->opt_sn_name);