mirror of
https://github.com/profanity-im/profanity.git
synced 2024-12-04 14:46:46 -05:00
Get rid of asprintf and _GNU_SOURCE define
_GNU_SOURCE was even in some files where it was not needed at all (http*). Let's replace asprintf() with g_strdup_printf().
This commit is contained in:
parent
3c1e4bac3a
commit
1ec606540e
@ -36,8 +36,6 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#define _GNU_SOURCE 1
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
@ -1558,13 +1556,15 @@ cmd_ac_complete_filepath(const char* const input, char* const startstr, gboolean
|
||||
|
||||
// expand ~ to $HOME
|
||||
if (inpcp[0] == '~' && inpcp[1] == '/') {
|
||||
if (asprintf(&tmp, "%s/%sfoo", getenv("HOME"), inpcp + 2) == -1) {
|
||||
tmp = g_strdup_printf("%s/%sfoo", getenv("HOME"), inpcp + 2);
|
||||
if (!tmp) {
|
||||
free(inpcp);
|
||||
return NULL;
|
||||
}
|
||||
output_off = strlen(getenv("HOME")) + 1;
|
||||
} else {
|
||||
if (asprintf(&tmp, "%sfoo", inpcp) == -1) {
|
||||
tmp = g_strdup_printf("%sfoo", inpcp);
|
||||
if (!tmp) {
|
||||
free(inpcp);
|
||||
return NULL;
|
||||
}
|
||||
@ -1596,25 +1596,29 @@ cmd_ac_complete_filepath(const char* const input, char* const startstr, gboolean
|
||||
|
||||
char* acstring;
|
||||
if (output_off) {
|
||||
if (asprintf(&tmp, "%s/%s", directory, dir->d_name) == -1) {
|
||||
tmp = g_strdup_printf("%s/%s", directory, dir->d_name);
|
||||
if(!tmp) {
|
||||
free(directory);
|
||||
free(foofile);
|
||||
return NULL;
|
||||
}
|
||||
if (asprintf(&acstring, "~/%s", tmp + output_off) == -1) {
|
||||
acstring = g_strdup_printf("~/%s", tmp + output_off);
|
||||
if (!acstring) {
|
||||
free(directory);
|
||||
free(foofile);
|
||||
return NULL;
|
||||
}
|
||||
free(tmp);
|
||||
} else if (strcmp(directory, "/") == 0) {
|
||||
if (asprintf(&acstring, "/%s", dir->d_name) == -1) {
|
||||
acstring = g_strdup_printf("/%s", dir->d_name);
|
||||
if (!acstring) {
|
||||
free(directory);
|
||||
free(foofile);
|
||||
return NULL;
|
||||
}
|
||||
} else {
|
||||
if (asprintf(&acstring, "%s/%s", directory, dir->d_name) == -1) {
|
||||
acstring = g_strdup_printf("%s/%s", directory, dir->d_name);
|
||||
if (!acstring) {
|
||||
free(directory);
|
||||
free(foofile);
|
||||
return NULL;
|
||||
|
@ -34,8 +34,6 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#define _GNU_SOURCE 1
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <assert.h>
|
||||
@ -2894,11 +2892,11 @@ command_mangen(void)
|
||||
|
||||
mkdir_recursive("docs");
|
||||
|
||||
char* header = NULL;
|
||||
GDateTime* now = g_date_time_new_now_local();
|
||||
gchar* date = g_date_time_format(now, "%F");
|
||||
if (asprintf(&header, ".TH man 1 \"%s\" \"" PACKAGE_VERSION "\" \"Profanity XMPP client\"\n", date) == -1) {
|
||||
// TODO: error
|
||||
gchar *header = g_strdup_printf(".TH man 1 \"%s\" \"" PACKAGE_VERSION "\" \"Profanity XMPP client\"\n", date);
|
||||
if (!header) {
|
||||
log_error("command_mangen(): could not allocate memory");
|
||||
return;
|
||||
}
|
||||
g_date_time_unref(now);
|
||||
@ -2908,9 +2906,9 @@ command_mangen(void)
|
||||
while (curr) {
|
||||
Command* pcmd = curr->data;
|
||||
|
||||
char* filename = NULL;
|
||||
if (asprintf(&filename, "docs/profanity-%s.1", &pcmd->cmd[1]) == -1) {
|
||||
// TODO: error
|
||||
gchar* filename = g_strdup_printf("docs/profanity-%s.1", &pcmd->cmd[1]);
|
||||
if (!filename) {
|
||||
log_error("command_mangen(): could not allocate memory");
|
||||
return;
|
||||
}
|
||||
FILE* manpage = fopen(filename, "w");
|
||||
@ -2955,6 +2953,6 @@ command_mangen(void)
|
||||
|
||||
printf("\nProcessed %d commands.\n\n", g_list_length(cmds));
|
||||
|
||||
free(header);
|
||||
g_free(header);
|
||||
g_list_free(cmds);
|
||||
}
|
||||
|
@ -35,8 +35,6 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#define _GNU_SOURCE 1
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <string.h>
|
||||
@ -141,10 +139,10 @@ cmd_process_input(ProfWin* window, char* inp)
|
||||
char* question_mark = strchr(command, '?');
|
||||
if (question_mark) {
|
||||
*question_mark = '\0';
|
||||
char* fakeinp;
|
||||
if (asprintf(&fakeinp, "/help %s", command + 1)) {
|
||||
gchar* fakeinp = g_strdup_printf("/help %s", command + 1);
|
||||
if (fakeinp) {
|
||||
result = _cmd_execute(window, "/help", fakeinp);
|
||||
free(fakeinp);
|
||||
g_free(fakeinp);
|
||||
}
|
||||
} else {
|
||||
result = _cmd_execute(window, command, inp);
|
||||
|
@ -34,8 +34,6 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#define _GNU_SOURCE 1
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <errno.h>
|
||||
@ -529,13 +527,14 @@ _unique_filename(const char* filename)
|
||||
|
||||
unsigned int i = 0;
|
||||
while (g_file_test(unique, G_FILE_TEST_EXISTS)) {
|
||||
free(unique);
|
||||
g_free(unique);
|
||||
|
||||
if (i > 1000) { // Give up after 1000 attempts.
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (asprintf(&unique, "%s.%u", filename, i) < 0) {
|
||||
unique = g_strdup_printf("%s.%u", filename, i);
|
||||
if (!unique) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -35,8 +35,6 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#define _GNU_SOURCE 1
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <sqlite3.h>
|
||||
#include <glib.h>
|
||||
@ -213,13 +211,14 @@ GSList*
|
||||
log_database_get_previous_chat(const gchar* const contact_barejid)
|
||||
{
|
||||
sqlite3_stmt* stmt = NULL;
|
||||
char* query;
|
||||
gchar* query;
|
||||
const char* jid = connection_get_fulljid();
|
||||
Jid* myjid = jid_create(jid);
|
||||
if (!myjid)
|
||||
return NULL;
|
||||
|
||||
if (asprintf(&query, "SELECT * FROM (SELECT `message`, `timestamp`, `from_jid`, `type` from `ChatLogs` WHERE (`from_jid` = '%s' AND `to_jid` = '%s') OR (`from_jid` = '%s' AND `to_jid` = '%s') ORDER BY `timestamp` DESC LIMIT 10) ORDER BY `timestamp` ASC;", contact_barejid, myjid->barejid, myjid->barejid, contact_barejid) == -1) {
|
||||
query = g_strdup_printf("SELECT * FROM (SELECT `message`, `timestamp`, `from_jid`, `type` from `ChatLogs` WHERE (`from_jid` = '%s' AND `to_jid` = '%s') OR (`from_jid` = '%s' AND `to_jid` = '%s') ORDER BY `timestamp` DESC LIMIT 10) ORDER BY `timestamp` ASC;", contact_barejid, myjid->barejid, myjid->barejid, contact_barejid);
|
||||
if (!query) {
|
||||
log_error("log_database_get_previous_chat(): SQL query. could not allocate memory");
|
||||
return NULL;
|
||||
}
|
||||
@ -251,7 +250,7 @@ log_database_get_previous_chat(const gchar* const contact_barejid)
|
||||
history = g_slist_append(history, msg);
|
||||
}
|
||||
sqlite3_finalize(stmt);
|
||||
free(query);
|
||||
g_free(query);
|
||||
|
||||
return history;
|
||||
}
|
||||
@ -314,7 +313,7 @@ _add_to_db(ProfMessage* message, char* type, const Jid* const from_jid, const Ji
|
||||
}
|
||||
|
||||
char* err_msg;
|
||||
char* query;
|
||||
gchar* query;
|
||||
gchar* date_fmt;
|
||||
|
||||
if (message->timestamp) {
|
||||
@ -331,7 +330,7 @@ _add_to_db(ProfMessage* message, char* type, const Jid* const from_jid, const Ji
|
||||
|
||||
char* escaped_message = str_replace(message->plain, "'", "''");
|
||||
|
||||
if (asprintf(&query, "INSERT INTO `ChatLogs` (`from_jid`, `from_resource`, `to_jid`, `to_resource`, `message`, `timestamp`, `stanza_id`, `archive_id`, `replace_id`, `type`, `encryption`) SELECT '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s' WHERE NOT EXISTS (SELECT 1 FROM `ChatLogs` WHERE `archive_id` = '%s')",
|
||||
query = g_strdup_printf("INSERT INTO `ChatLogs` (`from_jid`, `from_resource`, `to_jid`, `to_resource`, `message`, `timestamp`, `stanza_id`, `archive_id`, `replace_id`, `type`, `encryption`) SELECT '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s' WHERE NOT EXISTS (SELECT 1 FROM `ChatLogs` WHERE `archive_id` = '%s')",
|
||||
from_jid->barejid,
|
||||
from_jid->resourcepart ? from_jid->resourcepart : "",
|
||||
to_jid->barejid,
|
||||
@ -343,8 +342,8 @@ _add_to_db(ProfMessage* message, char* type, const Jid* const from_jid, const Ji
|
||||
message->replace_id ? message->replace_id : "",
|
||||
type ? type : "",
|
||||
enc ? enc : "",
|
||||
message->stanzaid ? message->stanzaid : "")
|
||||
== -1) {
|
||||
message->stanzaid ? message->stanzaid : "");
|
||||
if (!query) {
|
||||
log_error("log_database_add(): SQL query. could not allocate memory");
|
||||
return;
|
||||
}
|
||||
@ -359,5 +358,5 @@ _add_to_db(ProfMessage* message, char* type, const Jid* const from_jid, const Ji
|
||||
log_error("Unknown SQLite error");
|
||||
}
|
||||
}
|
||||
free(query);
|
||||
g_free(query);
|
||||
}
|
||||
|
@ -34,8 +34,6 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#define _GNU_SOURCE 1
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
@ -35,7 +35,6 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#define _GNU_SOURCE
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@ -315,11 +314,13 @@ _autocomplete_param_common(const char* const input, char* command, autocomplete_
|
||||
char* result = NULL;
|
||||
int len;
|
||||
|
||||
len = asprintf(&command_cpy, "%s ", command);
|
||||
if (len == -1) {
|
||||
command_cpy = g_strdup_printf("%s ", command);
|
||||
if (!command_cpy) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
len = strlen(command_cpy);
|
||||
|
||||
if (strncmp(input, command_cpy, len) == 0) {
|
||||
int inp_len = strlen(input);
|
||||
char prefix[inp_len];
|
||||
|
@ -35,8 +35,6 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#define _GNU_SOURCE 1
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
@ -34,8 +34,6 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#define _GNU_SOURCE 1
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
@ -33,8 +33,6 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#define _GNU_SOURCE 1
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
@ -92,12 +90,12 @@ _xferinfo(void* userdata, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultot
|
||||
ulperc = (100 * ulnow) / ultotal;
|
||||
}
|
||||
|
||||
char* msg;
|
||||
if (asprintf(&msg, "Uploading '%s': %d%%", upload->filename, ulperc) == -1) {
|
||||
msg = strdup(FALLBACK_MSG);
|
||||
gchar* msg = g_strdup_printf("Uploading '%s': %d%%", upload->filename, ulperc);
|
||||
if (!msg) {
|
||||
msg = g_strdup(FALLBACK_MSG);
|
||||
}
|
||||
win_update_entry_message(upload->window, upload->put_url, msg);
|
||||
free(msg);
|
||||
g_free(msg);
|
||||
|
||||
pthread_mutex_unlock(&lock);
|
||||
|
||||
@ -165,11 +163,11 @@ http_file_put(void* userdata)
|
||||
FILE* fh = NULL;
|
||||
|
||||
char* err = NULL;
|
||||
char* content_type_header;
|
||||
gchar* content_type_header;
|
||||
// Optional headers
|
||||
char* auth_header = NULL;
|
||||
char* cookie_header = NULL;
|
||||
char* expires_header = NULL;
|
||||
gchar* auth_header = NULL;
|
||||
gchar* cookie_header = NULL;
|
||||
gchar* expires_header = NULL;
|
||||
|
||||
CURL* curl;
|
||||
CURLcode res;
|
||||
@ -178,12 +176,12 @@ http_file_put(void* userdata)
|
||||
upload->bytes_sent = 0;
|
||||
|
||||
pthread_mutex_lock(&lock);
|
||||
char* msg;
|
||||
if (asprintf(&msg, "Uploading '%s': 0%%", upload->filename) == -1) {
|
||||
msg = strdup(FALLBACK_MSG);
|
||||
gchar* msg = g_strdup_printf("Uploading '%s': 0%%", upload->filename);
|
||||
if (!msg) {
|
||||
msg = g_strdup(FALLBACK_MSG);
|
||||
}
|
||||
win_print_http_transfer(upload->window, msg, upload->put_url);
|
||||
free(msg);
|
||||
g_free(msg);
|
||||
|
||||
char* cert_path = prefs_get_string(PREF_TLS_CERTPATH);
|
||||
pthread_mutex_unlock(&lock);
|
||||
@ -195,28 +193,32 @@ http_file_put(void* userdata)
|
||||
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "PUT");
|
||||
|
||||
struct curl_slist* headers = NULL;
|
||||
if (asprintf(&content_type_header, "Content-Type: %s", upload->mime_type) == -1) {
|
||||
content_type_header = strdup(FALLBACK_CONTENTTYPE_HEADER);
|
||||
content_type_header = g_strdup_printf("Content-Type: %s", upload->mime_type);
|
||||
if (content_type_header) {
|
||||
content_type_header = g_strdup(FALLBACK_CONTENTTYPE_HEADER);
|
||||
}
|
||||
headers = curl_slist_append(headers, content_type_header);
|
||||
headers = curl_slist_append(headers, "Expect:");
|
||||
|
||||
// Optional headers
|
||||
if (upload->authorization) {
|
||||
if (asprintf(&auth_header, "Authorization: %s", upload->authorization) == -1) {
|
||||
auth_header = strdup(FALLBACK_MSG);
|
||||
auth_header = g_strdup_printf("Authorization: %s", upload->authorization);
|
||||
if (!auth_header) {
|
||||
auth_header = g_strdup(FALLBACK_MSG);
|
||||
}
|
||||
headers = curl_slist_append(headers, auth_header);
|
||||
}
|
||||
if (upload->cookie) {
|
||||
if (asprintf(&cookie_header, "Cookie: %s", upload->cookie) == -1) {
|
||||
cookie_header = strdup(FALLBACK_MSG);
|
||||
cookie_header = g_strdup_printf("Cookie: %s", upload->cookie);
|
||||
if (!cookie_header) {
|
||||
cookie_header = g_strdup(FALLBACK_MSG);
|
||||
}
|
||||
headers = curl_slist_append(headers, cookie_header);
|
||||
}
|
||||
if (upload->expires) {
|
||||
if (asprintf(&expires_header, "Expires: %s", upload->expires) == -1) {
|
||||
expires_header = strdup(FALLBACK_MSG);
|
||||
expires_header = g_strdup_printf("Expires: %s", upload->expires);
|
||||
if (!expires_header) {
|
||||
expires_header = g_strdup(FALLBACK_MSG);
|
||||
}
|
||||
headers = curl_slist_append(headers, expires_header);
|
||||
}
|
||||
@ -262,9 +264,7 @@ http_file_put(void* userdata)
|
||||
|
||||
// XEP-0363 specifies 201 but prosody returns 200
|
||||
if (http_code != 200 && http_code != 201) {
|
||||
if (asprintf(&err, "Server returned %lu", http_code) == -1) {
|
||||
err = NULL;
|
||||
}
|
||||
err = g_strdup_printf("Server returned %lu", http_code);
|
||||
}
|
||||
|
||||
#if 0
|
||||
@ -281,47 +281,50 @@ http_file_put(void* userdata)
|
||||
if (fh) {
|
||||
fclose(fh);
|
||||
}
|
||||
free(content_type_header);
|
||||
free(output.buffer);
|
||||
free(auth_header);
|
||||
free(cookie_header);
|
||||
free(expires_header);
|
||||
g_free(content_type_header);
|
||||
g_free(auth_header);
|
||||
g_free(cookie_header);
|
||||
g_free(expires_header);
|
||||
|
||||
pthread_mutex_lock(&lock);
|
||||
g_free(cert_path);
|
||||
|
||||
if (err) {
|
||||
char* msg;
|
||||
gchar* msg;
|
||||
if (upload->cancel) {
|
||||
if (asprintf(&msg, "Uploading '%s' failed: Upload was canceled", upload->filename) == -1) {
|
||||
msg = strdup(FALLBACK_MSG);
|
||||
msg = g_strdup_printf("Uploading '%s' failed: Upload was canceled", upload->filename);
|
||||
if (!msg) {
|
||||
msg = g_strdup(FALLBACK_MSG);
|
||||
}
|
||||
} else {
|
||||
if (asprintf(&msg, "Uploading '%s' failed: %s", upload->filename, err) == -1) {
|
||||
msg = strdup(FALLBACK_MSG);
|
||||
msg = g_strdup_printf("Uploading '%s' failed: %s", upload->filename, err);
|
||||
if (!msg) {
|
||||
msg = g_strdup(FALLBACK_MSG);
|
||||
}
|
||||
win_update_entry_message(upload->window, upload->put_url, msg);
|
||||
}
|
||||
cons_show_error(msg);
|
||||
free(msg);
|
||||
g_free(msg);
|
||||
free(err);
|
||||
} else {
|
||||
if (!upload->cancel) {
|
||||
if (asprintf(&msg, "Uploading '%s': 100%%", upload->filename) == -1) {
|
||||
msg = strdup(FALLBACK_MSG);
|
||||
msg = g_strdup_printf("Uploading '%s': 100%%", upload->filename);
|
||||
if (!msg) {
|
||||
msg = g_strdup(FALLBACK_MSG);
|
||||
}
|
||||
win_update_entry_message(upload->window, upload->put_url, msg);
|
||||
win_mark_received(upload->window, upload->put_url);
|
||||
free(msg);
|
||||
g_free(msg);
|
||||
|
||||
char* url = NULL;
|
||||
if (format_alt_url(upload->get_url, upload->alt_scheme, upload->alt_fragment, &url) != 0) {
|
||||
char* msg;
|
||||
if (asprintf(&msg, "Uploading '%s' failed: Bad URL ('%s')", upload->filename, upload->get_url) == -1) {
|
||||
msg = strdup(FALLBACK_MSG);
|
||||
gchar* msg = g_strdup_printf("Uploading '%s' failed: Bad URL ('%s')", upload->filename, upload->get_url);
|
||||
if (!msg) {
|
||||
msg = g_strdup(FALLBACK_MSG);
|
||||
}
|
||||
cons_show_error(msg);
|
||||
free(msg);
|
||||
g_free(msg);
|
||||
} else {
|
||||
switch (upload->window->type) {
|
||||
case WIN_CHAT:
|
||||
|
@ -37,7 +37,6 @@
|
||||
#include "config.h"
|
||||
|
||||
#include "ui.h"
|
||||
#define _GNU_SOURCE 1
|
||||
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
@ -33,8 +33,6 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#define _GNU_SOURCE 1
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#ifdef HAVE_GIT_VERSION
|
||||
@ -242,10 +240,10 @@ stanza_create_http_upload_request(xmpp_ctx_t* ctx, const char* const id,
|
||||
xmpp_stanza_set_attribute(request, STANZA_ATTR_FILENAME, basename(filename_cpy));
|
||||
free(filename_cpy);
|
||||
|
||||
char* filesize = NULL;
|
||||
if (asprintf(&filesize, "%jd", (intmax_t)(upload->filesize)) != -1) {
|
||||
gchar* filesize = g_strdup_printf("%jd", (intmax_t)(upload->filesize));
|
||||
if (filesize) {
|
||||
xmpp_stanza_set_attribute(request, STANZA_ATTR_SIZE, filesize);
|
||||
free(filesize);
|
||||
g_free(filesize);
|
||||
}
|
||||
|
||||
xmpp_stanza_set_attribute(request, STANZA_ATTR_CONTENTTYPE, upload->mime_type);
|
||||
|
Loading…
Reference in New Issue
Block a user