mirror of
https://github.com/javalsai/lidm.git
synced 2025-07-03 14:25:03 +02:00
lint: satisfy some nullability annotations
This commit is contained in:
parent
4e18df55bf
commit
2bdb57390d
@ -1,5 +1,7 @@
|
|||||||
Checks: >
|
Checks: >
|
||||||
clang-analyzer-*,
|
clang-analyzer-*,
|
||||||
|
-clang-analyzer-security.insecureAPI.str*,
|
||||||
|
-clang-analyzer-security.insecureAPI.mem*,
|
||||||
bugprone-*,
|
bugprone-*,
|
||||||
cert-*,
|
cert-*,
|
||||||
modernize-*,
|
modernize-*,
|
||||||
|
@ -11,8 +11,9 @@ struct status {
|
|||||||
int ret;
|
int ret;
|
||||||
};
|
};
|
||||||
|
|
||||||
int read_desktop(FILE* fd, void* ctx,
|
int read_desktop(FILE* NNULLABLE fd, void* UNULLABLE ctx,
|
||||||
struct status (*cb)(void* ctx, char* NULLABLE table, char* key,
|
struct status (*NNULLABLE cb)(void* UNULLABLE ctx, char* NULLABLE table,
|
||||||
char* value));
|
char* NNULLABLE key,
|
||||||
|
char* NNULLABLE value));
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -10,3 +10,9 @@
|
|||||||
#else
|
#else
|
||||||
#define NNULLABLE
|
#define NNULLABLE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(__clang__)
|
||||||
|
#define UNULLABLE _Null_unspecified
|
||||||
|
#else
|
||||||
|
#define UNULLABLE
|
||||||
|
#endif
|
||||||
|
@ -7,18 +7,8 @@
|
|||||||
#include "desktop.h"
|
#include "desktop.h"
|
||||||
#include "macros.h"
|
#include "macros.h"
|
||||||
|
|
||||||
#define NOK \
|
|
||||||
{ \
|
|
||||||
ret = -1; \
|
|
||||||
break; \
|
|
||||||
}
|
|
||||||
#define NOKFKEY \
|
|
||||||
{ \
|
|
||||||
free(key); \
|
|
||||||
NOK \
|
|
||||||
}
|
|
||||||
int read_desktop(FILE* fd, void* ctx,
|
int read_desktop(FILE* fd, void* ctx,
|
||||||
struct status (*cb)(void* ctx, char* NULLABLE table, char* key,
|
struct status (*cb)(void* ctx, char* table, char* key,
|
||||||
char* value)) {
|
char* value)) {
|
||||||
char* table_name = NULL;
|
char* table_name = NULL;
|
||||||
|
|
||||||
@ -47,7 +37,10 @@ int read_desktop(FILE* fd, void* ctx,
|
|||||||
// impossible with a min len of 1 (empty line)
|
// impossible with a min len of 1 (empty line)
|
||||||
if (eq_idx == 0) continue;
|
if (eq_idx == 0) continue;
|
||||||
// Check its not end
|
// Check its not end
|
||||||
if (buf[eq_idx] != '=') NOK;
|
if (buf[eq_idx] != '=') {
|
||||||
|
ret = -1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
// Key & Value
|
// Key & Value
|
||||||
char* key = buf;
|
char* key = buf;
|
||||||
@ -64,11 +57,8 @@ int read_desktop(FILE* fd, void* ctx,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
free(table_name);
|
if (table_name != NULL) free(table_name);
|
||||||
|
|
||||||
if (buf != NULL) free(buf);
|
if (buf != NULL) free(buf);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
#undef NOK
|
|
||||||
#undef NOKFKEY
|
|
||||||
// NOLINTEND(clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling,readability-function-cognitive-complexity)
|
// NOLINTEND(clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling,readability-function-cognitive-complexity)
|
||||||
|
@ -20,22 +20,16 @@ static const struct source_dir sources[] = {
|
|||||||
{WAYLAND, "/usr/share/wayland-sessions"},
|
{WAYLAND, "/usr/share/wayland-sessions"},
|
||||||
};
|
};
|
||||||
|
|
||||||
// static struct session new_session(enum session_type type, char* name,
|
|
||||||
// const char* exec, const char* tryexec) {
|
|
||||||
// struct session session;
|
|
||||||
// session.type = type;
|
|
||||||
// strcln(&session.name, name);
|
|
||||||
// strcln(&session.exec, exec);
|
|
||||||
// strcln(&session.tryexec, tryexec);
|
|
||||||
|
|
||||||
// return session;
|
|
||||||
// }
|
|
||||||
|
|
||||||
static struct Vector* cb_sessions = NULL;
|
static struct Vector* cb_sessions = NULL;
|
||||||
|
|
||||||
|
struct ctx_typ {
|
||||||
|
char* NULLABLE name;
|
||||||
|
char* NULLABLE exec;
|
||||||
|
char* NULLABLE tryexec;
|
||||||
|
};
|
||||||
// NOLINTNEXTLINE(bugprone-easily-swappable-parameters)
|
// NOLINTNEXTLINE(bugprone-easily-swappable-parameters)
|
||||||
struct status cb(void* _ctx, char* NULLABLE table, char* key, char* value) {
|
struct status cb(void* _ctx, char* NULLABLE table, char* key, char* value) {
|
||||||
struct session* ctx = (struct session*)_ctx;
|
struct ctx_typ* ctx = (struct ctx_typ*)_ctx;
|
||||||
struct status ret;
|
struct status ret;
|
||||||
ret.finish = false;
|
ret.finish = false;
|
||||||
|
|
||||||
@ -52,13 +46,11 @@ struct status cb(void* _ctx, char* NULLABLE table, char* key, char* value) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (copy_at != NULL) {
|
if (copy_at != NULL) {
|
||||||
*copy_at = malloc((strlen(value) + 1) * sizeof(char));
|
*copy_at = strdup(value);
|
||||||
if (*copy_at == NULL) {
|
if (*copy_at == NULL) {
|
||||||
ret.finish = true;
|
ret.finish = true;
|
||||||
ret.ret = -1; // malloc error
|
ret.ret = -1; // malloc error
|
||||||
}
|
}
|
||||||
|
|
||||||
strcpy(*copy_at, value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ctx->name != NULL && ctx->exec != NULL && ctx->tryexec != NULL) {
|
if (ctx->name != NULL && ctx->exec != NULL && ctx->tryexec != NULL) {
|
||||||
@ -69,38 +61,50 @@ struct status cb(void* _ctx, char* NULLABLE table, char* key, char* value) {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// also, always return 0 or we will break parsing and we don't want a bad
|
||||||
|
// desktop file to break all possible sessions
|
||||||
static enum session_type session_type;
|
static enum session_type session_type;
|
||||||
// NOLINTNEXTLINE(readability-function-cognitive-complexity)
|
// NOLINTNEXTLINE(readability-function-cognitive-complexity)
|
||||||
static int fn(const char* fpath, const struct stat* sb, int typeflag) {
|
static int fn(const char* fpath, const struct stat* sb, int typeflag) {
|
||||||
if (!S_ISREG(sb->st_mode)) return 0;
|
// guessing symlink behavior
|
||||||
|
// - FTW_PHYS if set doesn't follow symlinks, so ftw() has no flags and it
|
||||||
|
// follows symlinks, we should never get to handle that
|
||||||
|
if (typeflag != FTW_F) return 0;
|
||||||
|
|
||||||
struct session* ctx = malloc(sizeof(struct session));
|
struct ctx_typ ctx = {
|
||||||
if (ctx == NULL) return 0;
|
.name = NULL,
|
||||||
ctx->name = NULL;
|
.exec = NULL,
|
||||||
ctx->exec = NULL;
|
.tryexec = NULL,
|
||||||
ctx->tryexec = NULL;
|
};
|
||||||
|
|
||||||
FILE* fd = fopen(fpath, "r");
|
FILE* fd = fopen(fpath, "r");
|
||||||
if (fd == NULL) {
|
if (fd == NULL) {
|
||||||
free(ctx);
|
|
||||||
perror("fopen");
|
perror("fopen");
|
||||||
// NOLINTNEXTLINE(clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling)
|
// NOLINTNEXTLINE(clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling)
|
||||||
(void)fprintf(stderr, "error opening file (r) '%s'\n", fpath);
|
(void)fprintf(stderr, "error opening file '%s' for read\n", fpath);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ret = read_desktop(fd, ctx, &cb);
|
int ret = read_desktop(fd, &ctx, &cb);
|
||||||
if (ret < 0) { // any error
|
if (ret < 0) { // any error
|
||||||
free(ctx);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
(void)fclose(fd);
|
(void)fclose(fd);
|
||||||
|
|
||||||
// just add this to the list
|
// just add this to the list
|
||||||
if (ctx->name != NULL && ctx->exec != NULL) {
|
if (ctx.name != NULL && ctx.exec != NULL) {
|
||||||
ctx->type = session_type;
|
struct session* this_session = malloc(sizeof(struct session));
|
||||||
vec_push(cb_sessions, ctx);
|
if (this_session == NULL) return 0;
|
||||||
|
|
||||||
|
*this_session = (struct session){
|
||||||
|
.name = ctx.name,
|
||||||
|
.exec = ctx.exec,
|
||||||
|
.tryexec = ctx.tryexec,
|
||||||
|
.type = session_type,
|
||||||
|
};
|
||||||
|
|
||||||
|
vec_push(cb_sessions, this_session);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user