{"action":"created","issue":{"url":"https://api.github.com/repos/neomutt/neomutt/issues/250","repository_url":"https://api.github.com/repos/neomutt/neomutt","labels_url":"https://api.github.com/repos/neomutt/neomutt/issues/250/labels{/name}","comments_url":"https://api.github.com/repos/neomutt/neomutt/issues/250/comments","events_url":"https://api.github.com/repos/neomutt/neomutt/issues/250/events","html_url":"https://github.com/neomutt/neomutt/issues/250","id":190348724,"number":250,"title":"Do not force unsigned chars as param to mutt_to_base64","user":{"login":"gahr","id":959474,"avatar_url":"https://avatars.githubusercontent.com/u/959474?v=3","gravatar_id":"","url":"https://api.github.com/users/gahr","html_url":"https://github.com/gahr","followers_url":"https://api.github.com/users/gahr/followers","following_url":"https://api.github.com/users/gahr/following{/other_user}","gists_url":"https://api.github.com/users/gahr/gists{/gist_id}","starred_url":"https://api.github.com/users/gahr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gahr/subscriptions","organizations_url":"https://api.github.com/users/gahr/orgs","repos_url":"https://api.github.com/users/gahr/repos","events_url":"https://api.github.com/users/gahr/events{/privacy}","received_events_url":"https://api.github.com/users/gahr/received_events","type":"User","site_admin":false},"labels":[{"id":371456579,"url":"https://api.github.com/repos/neomutt/neomutt/labels/discussion","name":"discussion","color":"9f00bf","default":false},{"id":302065907,"url":"https://api.github.com/repos/neomutt/neomutt/labels/enhancement","name":"enhancement","color":"fbca04","default":true}],"state":"open","locked":false,"assignee":{"login":"gahr","id":959474,"avatar_url":"https://avatars.githubusercontent.com/u/959474?v=3","gravatar_id":"","url":"https://api.github.com/users/gahr","html_url":"https://github.com/gahr","followers_url":"https://api.github.com/users/gahr/followers","following_url":"https://api.github.com/users/gahr/following{/other_user}","gists_url":"https://api.github.com/users/gahr/gists{/gist_id}","starred_url":"https://api.github.com/users/gahr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gahr/subscriptions","organizations_url":"https://api.github.com/users/gahr/orgs","repos_url":"https://api.github.com/users/gahr/repos","events_url":"https://api.github.com/users/gahr/events{/privacy}","received_events_url":"https://api.github.com/users/gahr/received_events","type":"User","site_admin":false},"assignees":[{"login":"gahr","id":959474,"avatar_url":"https://avatars.githubusercontent.com/u/959474?v=3","gravatar_id":"","url":"https://api.github.com/users/gahr","html_url":"https://github.com/gahr","followers_url":"https://api.github.com/users/gahr/followers","following_url":"https://api.github.com/users/gahr/following{/other_user}","gists_url":"https://api.github.com/users/gahr/gists{/gist_id}","starred_url":"https://api.github.com/users/gahr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gahr/subscriptions","organizations_url":"https://api.github.com/users/gahr/orgs","repos_url":"https://api.github.com/users/gahr/repos","events_url":"https://api.github.com/users/gahr/events{/privacy}","received_events_url":"https://api.github.com/users/gahr/received_events","type":"User","site_admin":false}],"milestone":null,"comments":1,"created_at":"2016-11-18T15:37:22Z","updated_at":"2016-11-18T16:57:34Z","closed_at":null,"body":"`mutt_to_base64` takes `unsigned char` as input and output parameters. This forces callers to cast their (usually) simple `char` buffers, example:\r\n\r\n````c\r\nmutt_to_base64 ((unsigned char*) ibuf, (unsigned char*) obuf, strlen (obuf),\r\n               sizeof (ibuf) - 2);\r\n````\r\n\r\nLet's change `mutt_to_base64`'s signature and do the casting inside. While at it, also return the numbers of characters written to the output buffer, so anybody needing that information can avoid having to call `strlen`.\r\n\r\n````diff\r\ndiff --git a/base64.c b/base64.c\r\nindex fd3ffb8..d2ad0c0 100644\r\n--- a/base64.c\r\n+++ b/base64.c\r\n@@ -49,9 +49,10 @@\r\n #define BAD     -1\r\n\r\n /* raw bytes to null-terminated base 64 string */\r\n-void mutt_to_base64 (unsigned char *out, const unsigned char *in, size_t len,\r\n-                    size_t olen)\r\n+size_t mutt_to_base64 (char *out, const char *cin, size_t len, size_t olen)\r\n {\r\n+  unsigned char *begin = (unsigned char *)out;\r\n+  const unsigned char *in = (const unsigned char *)cin;\r\n   while (len >= 3 && olen > 10)\r\n   {\r\n     *out++ = B64Chars[in[0] >> 2];\r\n@@ -77,6 +78,7 @@ void mutt_to_base64 (unsigned char *out, const unsigned char *in, size_t len,\r\n     *out++ = '=';\r\n   }\r\n   *out = '\\0';\r\n+  return out - (char *)begin;\r\n }\r\n\r\n /* Convert '\\0'-terminated base 64 string to raw bytes.\r\n````"},"comment":{"url":"https://api.github.com/repos/neomutt/neomutt/issues/comments/261582938","html_url":"https://github.com/neomutt/neomutt/issues/250#issuecomment-261582938","issue_url":"https://api.github.com/repos/neomutt/neomutt/issues/250","id":261582938,"user":{"login":"gahr","id":959474,"avatar_url":"https://avatars.githubusercontent.com/u/959474?v=3","gravatar_id":"","url":"https://api.github.com/users/gahr","html_url":"https://github.com/gahr","followers_url":"https://api.github.com/users/gahr/followers","following_url":"https://api.github.com/users/gahr/following{/other_user}","gists_url":"https://api.github.com/users/gahr/gists{/gist_id}","starred_url":"https://api.github.com/users/gahr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gahr/subscriptions","organizations_url":"https://api.github.com/users/gahr/orgs","repos_url":"https://api.github.com/users/gahr/repos","events_url":"https://api.github.com/users/gahr/events{/privacy}","received_events_url":"https://api.github.com/users/gahr/received_events","type":"User","site_admin":false},"created_at":"2016-11-18T16:57:34Z","updated_at":"2016-11-18T16:57:34Z","body":"(rebased on top of neomutt, as I originally branched off the wrong branch)"}}
{"actor":{"display_login":"gahr"}}