aboutsummaryrefslogtreecommitdiffstats
path: root/protocols/twitter/twitter.c
diff options
context:
space:
mode:
authordequis <dx@dxzone.com.ar>2015-03-06 05:27:06 -0300
committerdequis <dx@dxzone.com.ar>2015-03-10 04:27:25 -0300
commit8b91a1f60f5d27c91d5a9939236e6078a090ef92 (patch)
tree169d28829011dcbc578987d29a482f1fced8b512 /protocols/twitter/twitter.c
parente6f47fb583ff077982c7321e3b699d749d787d6d (diff)
twitter: Fix twitter_parse_id to accept 00 as a valid tweet
Also fix the endptr condition which was backwards and resulted in every tweet id getting rejected, but you didn't see that one, this commit really is about the tweet id 00 which is the most important tweet id.
Diffstat (limited to 'protocols/twitter/twitter.c')
-rw-r--r--protocols/twitter/twitter.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/protocols/twitter/twitter.c b/protocols/twitter/twitter.c
index 891d07a6..95384573 100644
--- a/protocols/twitter/twitter.c
+++ b/protocols/twitter/twitter.c
@@ -851,18 +851,19 @@ static void twitter_buddy_data_free(struct bee_user *bu)
g_free(bu->data);
}
-/* Parses a decimal or hex tweet ID, handling errors by returning 0 */
-static guint64 twitter_parse_id(char *string, int base)
+/* Parses a decimal or hex tweet ID, returns TRUE on success */
+static gboolean twitter_parse_id(char *string, int base, guint64 *id)
{
guint64 parsed;
char *endptr;
errno = 0;
parsed = g_ascii_strtoull(string, &endptr, base);
- if (errno || endptr == string || *endptr == '\0') {
- return 0;
+ if (errno || endptr == string || *endptr != '\0') {
+ return FALSE;
}
- return parsed;
+ *id = parsed;
+ return TRUE;
}
/** Convert the given bitlbee tweet ID, bitlbee username, or twitter tweet ID
@@ -892,14 +893,14 @@ static guint64 twitter_message_id_from_command_arg(struct im_connection *ic, cha
if (arg[0] == '#') {
arg++;
}
- if ((id = twitter_parse_id(arg, 16)) && id < TWITTER_LOG_LENGTH) {
+ if (twitter_parse_id(arg, 16, &id) && id < TWITTER_LOG_LENGTH) {
bu = td->log[id].bu;
id = td->log[id].id;
/* Beware of dangling pointers! */
if (!g_slist_find(ic->bee->users, bu)) {
bu = NULL;
}
- } else if ((id = twitter_parse_id(arg, 10))) {
+ } else if (twitter_parse_id(arg, 10, &id)) {
/* Allow normal tweet IDs as well; not a very useful
feature but it's always been there. Just ignore
very low IDs to avoid accidents. */