* don't run into unused buffer parts.
authorWilfried Göesgens <willi@citadel.org>
Thu, 12 Feb 2009 23:56:20 +0000 (23:56 +0000)
committerWilfried Göesgens <willi@citadel.org>
Thu, 12 Feb 2009 23:56:20 +0000 (23:56 +0000)
webcit/calendar_view.c

index bd882d066a4bd6166d48ff50a864cca709837dc1..1c6d098c7aa55f136bab1877873efea42ae8af65 100644 (file)
@@ -146,16 +146,21 @@ void embeddable_mini_calendar(int year, int month, char *urlformat)
  * ajax embedder for the above mini calendar 
  */
 void ajax_mini_calendar(void) {
+       const StrBuf *Buf;
        char urlformat[256];
-       int i, len;
-       char *escaped_urlformat;
+       int i, j, len;
+       const char *escaped_urlformat;
 
-       escaped_urlformat = bstr("urlformat");
-        len = strlen(escaped_urlformat) * 2 ;
-       for (i=0; i<len; ++i) {
-               urlformat[i] = xtoi(&escaped_urlformat[i*2], 2);
-               urlformat[i+1] = 0;
+       Buf = sbstr("urlformat");
+       escaped_urlformat = ChrPtr(Buf);
+        len = StrLength(Buf);
+       if (len * 2 > sizeof(urlformat))
+               len = sizeof(urlformat) / 2;
+
+       for (i=0, j = 0; i < len ; i+=2, j++) {
+               urlformat[j] = xtoi(&escaped_urlformat[i], 2);
        }
+       urlformat[j] = '\0';
 
        embeddable_mini_calendar( ibstr("year"), ibstr("month"), urlformat );
 }