Merge pull request #290 from duskCoder/changes
Fix potential issues & avoid unnecessary instructions
This commit is contained in:
commit
4d3344ab9c
@ -106,7 +106,7 @@ static bool path_exists(const char *path) {
|
||||
|
||||
static void *scalloc(size_t size) {
|
||||
void *result = calloc(size, 1);
|
||||
exit_if_null(result, "Error: out of memory (calloc(%zd))\n", size);
|
||||
exit_if_null(result, "Error: out of memory (calloc(%zu))\n", size);
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -142,7 +142,7 @@ static int parse_min_width(cfg_t *context, cfg_opt_t *option, const char *value,
|
||||
long num = strtol(value, &end, 10);
|
||||
|
||||
if (num < 0)
|
||||
die("Invalid min_width attribute found in section %s, line %d: %d\n"
|
||||
die("Invalid min_width attribute found in section %s, line %d: %ld\n"
|
||||
"Expected positive integer or string\n",
|
||||
context->name, context->line, num);
|
||||
else if (num == LONG_MIN || num == LONG_MAX || (end && *end != '\0'))
|
||||
|
@ -186,7 +186,8 @@ char *sstrdup(const char *str);
|
||||
|
||||
/* src/general.c */
|
||||
char *skip_character(char *input, char character, int amount);
|
||||
void die(const char *fmt, ...);
|
||||
|
||||
void die(const char *fmt, ...) __attribute__((format(printf, 1, 2), noreturn));
|
||||
bool slurp(const char *filename, char *destination, int size);
|
||||
|
||||
/* src/output.c */
|
||||
|
@ -51,12 +51,10 @@ char *skip_character(char *input, char character, int amount) {
|
||||
*
|
||||
*/
|
||||
void die(const char *fmt, ...) {
|
||||
char buffer[512];
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
(void)vsnprintf(buffer, sizeof(buffer), fmt, ap);
|
||||
(void)vfprintf(stderr, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
fprintf(stderr, "%s", buffer);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
@ -450,14 +450,17 @@ static bool slurp_all_batteries(struct battery_info *batt_info, yajl_gen json_ge
|
||||
.present_rate = 0,
|
||||
.status = CS_UNKNOWN,
|
||||
};
|
||||
if (!slurp_battery_info(&batt_buf, json_gen, buffer, i, globbuf.gl_pathv[i], format_down))
|
||||
if (!slurp_battery_info(&batt_buf, json_gen, buffer, i, globbuf.gl_pathv[i], format_down)) {
|
||||
globfree(&globbuf);
|
||||
free(globpath);
|
||||
return false;
|
||||
}
|
||||
|
||||
is_found = true;
|
||||
add_battery_info(batt_info, &batt_buf);
|
||||
}
|
||||
globfree(&globbuf);
|
||||
}
|
||||
globfree(&globbuf);
|
||||
free(globpath);
|
||||
|
||||
if (!is_found) {
|
||||
|
@ -223,7 +223,7 @@ void print_cpu_temperature_info(yajl_gen json_gen, char *buffer, int zone, const
|
||||
asprintf(&thermal_zone, THERMAL_ZONE, zone);
|
||||
else {
|
||||
static glob_t globbuf;
|
||||
if (glob(path, GLOB_NOCHECK | GLOB_TILDE, NULL, &globbuf) < 0)
|
||||
if (glob(path, GLOB_NOCHECK | GLOB_TILDE, NULL, &globbuf) != 0)
|
||||
die("glob() failed\n");
|
||||
if (globbuf.gl_pathc == 0) {
|
||||
/* No glob matches, the specified path does not contain a wildcard. */
|
||||
|
@ -7,7 +7,7 @@
|
||||
#include <sys/stat.h>
|
||||
#include <sys/statvfs.h>
|
||||
#include <sys/types.h>
|
||||
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || (__OpenBSD__) || defined(__DragonFly__) || defined(__APPLE__)
|
||||
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__OpenBSD__) || defined(__DragonFly__) || defined(__APPLE__)
|
||||
#include <sys/param.h>
|
||||
#include <sys/mount.h>
|
||||
#elif defined(__NetBSD__)
|
||||
|
@ -39,10 +39,9 @@ static int print_bytes_human(char *outwalk, uint64_t bytes) {
|
||||
*
|
||||
*/
|
||||
static long memory_absolute(const long mem_total, const char *size) {
|
||||
long mem_absolute = -1;
|
||||
char *endptr = NULL;
|
||||
|
||||
mem_absolute = strtol(size, &endptr, 10);
|
||||
long mem_absolute = strtol(size, &endptr, 10);
|
||||
|
||||
if (endptr) {
|
||||
while (endptr[0] != '\0' && isspace(endptr[0]))
|
||||
|
@ -151,7 +151,7 @@ void print_volume(yajl_gen json_gen, char *buffer, const char *fmt, const char *
|
||||
snd_mixer_selem_id_set_index(sid, mixer_idx);
|
||||
snd_mixer_selem_id_set_name(sid, mixer);
|
||||
if (!(elem = snd_mixer_find_selem(m, sid))) {
|
||||
fprintf(stderr, "i3status: ALSA: Cannot find mixer %s (index %i)\n",
|
||||
fprintf(stderr, "i3status: ALSA: Cannot find mixer %s (index %u)\n",
|
||||
snd_mixer_selem_id_get_name(sid), snd_mixer_selem_id_get_index(sid));
|
||||
snd_mixer_close(m);
|
||||
snd_mixer_selem_id_free(sid);
|
||||
|
@ -24,7 +24,7 @@ bool process_runs(const char *path) {
|
||||
static glob_t globbuf;
|
||||
memset(pidbuf, 0, sizeof(pidbuf));
|
||||
|
||||
if (glob(path, GLOB_NOCHECK | GLOB_TILDE, NULL, &globbuf) < 0)
|
||||
if (glob(path, GLOB_NOCHECK | GLOB_TILDE, NULL, &globbuf) != 0)
|
||||
die("glob() failed\n");
|
||||
if (globbuf.gl_pathc == 0) {
|
||||
/* No glob matches, the specified path does not contain a wildcard. */
|
||||
|
Loading…
Reference in New Issue
Block a user