<<< Date Index >>>     <<< Thread Index >>>

Re: sscanf (x, "%u", &(uint64_t))



On Sat, 19 Mar 2005, YONETANI Tomokazu wrote:
> And it's always good to check the return value from a function if any.
> It can fail if the passed string does not represent an unsigned integer
> (and not even sure if sscanf() doesn't touch `validity' when it failed):
>   unsigned int validity = 0;
>       :
>   if (sscanf(pc, "%u", &validity) == 1)
>       idata->uid_validity = validity;
>   else
>       /* abort parsing any further; we can't trust what the server says */

Thanks, here is a totally untested patch.

-- 
tamo
--- imap/imap.c~        2005-02-18 21:43:21.000000000 +0900
+++ imap/imap.c 2005-03-19 17:32:50.240511360 +0900
@@ -632,10 +632,14 @@
     /* save UIDVALIDITY for the header cache */
     else if (ascii_strncasecmp("OK [UIDVALIDITY", pc, 14) == 0)
     {
+      unsigned int tmpvalidity = 0;
       dprint(2, (debugfile, "Getting mailbox UIDVALIDITY\n"));
       pc += 3;
       pc = imap_next_word(pc);
-      sscanf(pc, "%u", &(idata->uid_validity));
+      if (sscanf (pc, "%u", &tmpvalidity) == 1)
+       idata->uid_validity = tmpvalidity;
+      else
+       goto fail;
     }
 #endif
     else