Skip to content

Commit

Permalink
Ensure instances of auto types are initialized
Browse files Browse the repository at this point in the history
Follow-up of #1913

Signed-off-by: Steffen Jaeckel <[email protected]>
  • Loading branch information
sjaeckel committed Nov 6, 2023
1 parent 716c068 commit 5418f74
Show file tree
Hide file tree
Showing 13 changed files with 47 additions and 73 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ jobs:
continue-on-error: true
steps:
- uses: actions/checkout@v2
# if this check fails, you have to update the number of auto types known and the list of auto types in the check below
- name: Check auto types are up-to-date
run: |
[[ "$(find src -type f -name '*.[ch]' -exec awk '/^#define auto_[\W]*/ {print $2}' '{}' \; | sort -u | wc -l)" == "6" ]] || exit -1
- name: Check auto types are initialized
run: |
grep -P 'auto_(char|gchar|gcharv|guchar|jid|sqlite)[\w *]*;$' -r src && exit -1 || true
- name: Run clang-format
uses: jidicula/[email protected]
with:
Expand Down
6 changes: 2 additions & 4 deletions src/command/cmd_funcs.c
Original file line number Diff line number Diff line change
Expand Up @@ -4900,13 +4900,11 @@ gboolean
cmd_sendfile(ProfWin* window, const char* const command, gchar** args)
{
jabber_conn_status_t conn_status = connection_get_status();
auto_gchar gchar* filename;
// expand ~ to $HOME
auto_gchar gchar* filename = get_expanded_path(args[0]);
char* alt_scheme = NULL;
char* alt_fragment = NULL;

// expand ~ to $HOME
filename = get_expanded_path(args[0]);

if (access(filename, R_OK) != 0) {
cons_show_error("Uploading '%s' failed: File not found!", filename);
goto out;
Expand Down
2 changes: 1 addition & 1 deletion src/database.c
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ _add_to_db(ProfMessage* message, char* type, const Jid* const from_jid, const Ji
}

char* err_msg;
auto_gchar gchar* date_fmt;
auto_gchar gchar* date_fmt = NULL;

if (message->timestamp) {
date_fmt = g_date_time_format_iso8601(message->timestamp);
Expand Down
7 changes: 1 addition & 6 deletions src/omemo/omemo.c
Original file line number Diff line number Diff line change
Expand Up @@ -495,12 +495,7 @@ void
omemo_set_device_list(const char* const from, GList* device_list)
{
log_debug("[OMEMO] Setting device list for %s", STR_MAYBE_NULL(from));
auto_jid Jid* jid;
if (from) {
jid = jid_create(from);
} else {
jid = jid_create(connection_get_fulljid());
}
auto_jid Jid* jid = jid_create(from ?: connection_get_fulljid());

g_hash_table_insert(omemo_ctx.device_list, strdup(jid->barejid), device_list);

Expand Down
17 changes: 3 additions & 14 deletions src/ui/chatwin.c
Original file line number Diff line number Diff line change
Expand Up @@ -328,13 +328,7 @@ chatwin_incoming_msg(ProfChatWin* chatwin, ProfMessage* message, gboolean win_cr
ProfWin* window = (ProfWin*)chatwin;
int num = wins_get_num(window);

auto_gchar gchar* display_name;
auto_char char* mybarejid = connection_get_barejid();
if (g_strcmp0(mybarejid, message->from_jid->barejid) == 0) {
display_name = strdup("me");
} else {
display_name = roster_get_msg_display_name(message->from_jid->barejid, message->from_jid->resourcepart);
}
auto_gchar gchar* display_name = get_display_name(message, NULL);

#ifdef HAVE_LIBGPGME
if (prefs_get_boolean(PREF_PGP_PUBKEY_AUTOIMPORT)) {
Expand Down Expand Up @@ -430,12 +424,7 @@ chatwin_outgoing_msg(ProfChatWin* chatwin, const char* const message, char* id,
ProfWin* window = (ProfWin*)chatwin;
wins_add_quotes_ac(window, message, FALSE);

auto_char char* enc_char;
if (chatwin->outgoing_char) {
enc_char = chatwin->outgoing_char;
} else {
enc_char = get_show_char(enc_mode);
}
auto_char char* enc_char = get_enc_char(enc_mode, chatwin->outgoing_char);

if (request_receipt && id) {
win_print_outgoing_with_receipt((ProfWin*)chatwin, enc_char, "me", message, id, replace_id);
Expand All @@ -454,7 +443,7 @@ chatwin_outgoing_carbon(ProfChatWin* chatwin, ProfMessage* message)
{
assert(chatwin != NULL);

auto_char char* enc_char;
auto_char char* enc_char = NULL;
if (message->enc == PROF_MSG_ENC_PGP) {
enc_char = prefs_get_pgp_char();
} else if (message->enc == PROF_MSG_ENC_OMEMO) {
Expand Down
7 changes: 1 addition & 6 deletions src/ui/console.c
Original file line number Diff line number Diff line change
Expand Up @@ -2518,12 +2518,7 @@ cons_alert(ProfWin* alert_origin_window)
if (current->type != WIN_CONSOLE) {
status_bar_new(1, WIN_CONSOLE, "console");

auto_gchar gchar* win_name;
if (alert_origin_window) {
win_name = win_to_string(alert_origin_window);
} else {
win_name = g_strdup("console");
}
auto_gchar gchar* win_name = alert_origin_window ? win_to_string(alert_origin_window) : g_strdup("console");

GList* item = g_list_find_custom(alert_list, win_name, (GCompareFunc)g_strcmp0);
if (!item) {
Expand Down
14 changes: 2 additions & 12 deletions src/ui/mucwin.c
Original file line number Diff line number Diff line change
Expand Up @@ -515,12 +515,7 @@ mucwin_outgoing_msg(ProfMucWin* mucwin, const char* const message, const char* c
char* mynick = muc_nick(mucwin->roomjid);

// displayed message char
auto_char char* ch;
if (mucwin->message_char) {
ch = strdup(mucwin->message_char);
} else {
ch = get_show_char(enc_mode);
}
auto_char char* ch = get_enc_char(enc_mode, mucwin->message_char);

win_print_outgoing_muc_msg(window, ch, mynick, id, replace_id, message);

Expand Down Expand Up @@ -555,12 +550,7 @@ mucwin_incoming_msg(ProfMucWin* mucwin, const ProfMessage* const message, GSList
ProfWin* window = (ProfWin*)mucwin;
char* mynick = muc_nick(mucwin->roomjid);

auto_char char* ch;
if (mucwin->message_char) {
ch = strdup(mucwin->message_char);
} else {
ch = get_show_char(message->enc);
}
auto_char char* ch = get_enc_char(message->enc, mucwin->message_char);

win_insert_last_read_position_marker((ProfWin*)mucwin, mucwin->roomjid);
wins_add_urls_ac(window, message, FALSE);
Expand Down
40 changes: 12 additions & 28 deletions src/ui/window.c
Original file line number Diff line number Diff line change
Expand Up @@ -1389,14 +1389,8 @@ win_print_incoming(ProfWin* window, const char* const display_name_from, ProfMes
switch (window->type) {
case WIN_CHAT:
{
auto_char char* enc_char;
ProfChatWin* chatwin = (ProfChatWin*)window;

if (chatwin->incoming_char) {
enc_char = strdup(chatwin->incoming_char);
} else {
enc_char = get_show_char(message->enc);
}
auto_char char* enc_char = get_enc_char(message->enc, chatwin->incoming_char);

if (prefs_get_boolean(PREF_CORRECTION_ALLOW) && message->replace_id) {
_win_correct(window, message->plain, message->id, message->replace_id, message->from_jid->barejid);
Expand Down Expand Up @@ -1472,18 +1466,8 @@ win_print_history(ProfWin* window, const ProfMessage* const message)
{
g_date_time_ref(message->timestamp);

auto_gchar gchar* display_name;
int flags = 0;
const char* jid = connection_get_fulljid();
auto_jid Jid* jidp = jid_create(jid);

if (g_strcmp0(jidp->barejid, message->from_jid->barejid) == 0) {
display_name = strdup("me");
} else {
display_name = roster_get_msg_display_name(message->from_jid->barejid, message->from_jid->resourcepart);
flags = NO_ME;
}

auto_gchar gchar* display_name = get_display_name(message, &flags);
auto_char char* ch = get_show_char(message->enc);

buffer_append(window->layout->buffer, ch, 0, message->timestamp, flags, THEME_TEXT_HISTORY, display_name, NULL, message->plain, NULL, NULL);
Expand All @@ -1500,17 +1484,8 @@ win_print_old_history(ProfWin* window, const ProfMessage* const message)
{
g_date_time_ref(message->timestamp);

auto_char char* display_name;
int flags = 0;
const char* jid = connection_get_fulljid();
auto_jid Jid* jidp = jid_create(jid);

if (g_strcmp0(jidp->barejid, message->from_jid->barejid) == 0) {
display_name = strdup("me");
} else {
display_name = roster_get_msg_display_name(message->from_jid->barejid, message->from_jid->resourcepart);
flags = NO_ME;
}
auto_gchar gchar* display_name = get_display_name(message, &flags);

auto_char char* ch = get_show_char(message->enc);

Expand Down Expand Up @@ -2256,3 +2231,12 @@ get_show_char(prof_enc_t encryption_mode)

return enc_char;
}

char*
get_enc_char(prof_enc_t enc_mode, const char* alt)
{
if (alt)
return strdup(alt);
else
return get_show_char(enc_mode);
}
1 change: 1 addition & 0 deletions src/ui/window.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,5 +99,6 @@ void win_remove_entry_message(ProfWin* window, const char* const id);
char* win_quote_autocomplete(ProfWin* window, const char* const input, gboolean previous);

char* get_show_char(prof_enc_t encryption_mode);
char* get_enc_char(prof_enc_t enc_mode, const char* alt);

#endif
2 changes: 1 addition & 1 deletion src/xmpp/avatar.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ avatar_set(const char* path)
pixbuf = new_pixbuf;
}

auto_gchar gchar* img_data;
auto_gchar gchar* img_data = NULL;
gsize len = -1;

if (!gdk_pixbuf_save_to_buffer(pixbuf, &img_data, &len, "png", &err, NULL)) {
Expand Down
14 changes: 14 additions & 0 deletions src/xmpp/message.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,20 @@ static xmpp_stanza_t* _ox_openpgp_signcrypt(xmpp_ctx_t* ctx, const char* const t

static GHashTable* pubsub_event_handlers;

gchar*
get_display_name(const ProfMessage* const message, gboolean* flags)
{
auto_char char* barejid = connection_get_barejid();

if (g_strcmp0(barejid, message->from_jid->barejid) == 0) {
return g_strdup("me");
} else {
if (flags)
*flags = TRUE;
return roster_get_msg_display_name(message->from_jid->barejid, message->from_jid->resourcepart);
}
}

static gboolean
_handled_by_plugin(xmpp_stanza_t* const stanza)
{
Expand Down
2 changes: 1 addition & 1 deletion src/xmpp/vcard.c
Original file line number Diff line number Diff line change
Expand Up @@ -1350,7 +1350,7 @@ _vcard_photo_result(xmpp_stanza_t* const stanza, void* userdata)
}

if (data->open) {
auto_gcharv gchar** argv;
auto_gcharv gchar** argv = NULL;
gint argc;

auto_gchar gchar* cmdtemplate = prefs_get_string(PREF_VCARD_PHOTO_CMD);
Expand Down
1 change: 1 addition & 0 deletions src/xmpp/xmpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -317,4 +317,5 @@ void form_reset_autocompleters(DataForm* form);

void publish_user_mood(const char* const mood, const char* const text);

gchar* get_display_name(const ProfMessage* const message, gboolean* flags);
#endif

0 comments on commit 5418f74

Please sign in to comment.