Andy Dougherty:
# After just this little patch:  (line numbers are off due to 
# other unrelated fiddling on my part)
# 
# it compiles.  So far, I only have seen 2 failed tests:
# 
# The first is t/src/sprintf.t, which looks like an off-by-one 
# issue of some sort.  I haven't tracked it further yet.
# 
# There were also some compiler warnings that I'll try to track 
# down further, and I haven't tested things exhaustively, but 
# this sure looks like the way to go to me.  Thanks.

The following fixes all that, leaving just two warnings (on Cygwin) that
refuse to be casted away.  (It'll wrap, so check that you've removed all
the newlines before applying.)

--- ..\misc.c_old       Mon Oct  7 19:01:44 2002
+++ misc.c      Tue Oct  8 11:06:42 2002
@@ -24,15 +24,11 @@
 */
 #define PARROT_SPRINTF_MAX_PREC 3 * PARROT_SPRINTF_BUFFER_SIZE / 4

-#ifndef HAS_SNPRINTF
-    #ifdef _WIN32
-        #define snprintf _snprintf
-    #else
-        /* First platform to run into a problem with this gets to
-        ** supply the float handling code!  :^)
-        */
-        #define snprintf PANIC("No snprintf");
-    #endif
+/* Per Dan's orders, we will not use sprintf if snprintf isn't
+** around for us.
+*/
+#ifdef _WIN32
+    #define snprintf _snprintf
 #endif

 typedef struct spfinfo_t {
@@ -87,6 +83,9 @@
             PMC *pmc=(PMC*)va_arg(*args, PMC*);
             return
(HUGEINTVAL)(INTVAL)(pmc->vtable->get_integer(interpreter, pmc));
         }
+        default:
+            PANIC("Invalid int type!");
+            return 0;
     }
 }

@@ -108,6 +107,9 @@
             PMC* pmc=(PMC*)va_arg(*args, PMC*);
             return
(UHUGEINTVAL)(UINTVAL)(pmc->vtable->get_integer(interpreter, pmc));
\
         }
+        default:
+            PANIC("Invalid uint type!");
+            return 0;
     }
 }

@@ -179,8 +181,8 @@
 static void
 handle_flags(SpfInfo info, char *buf, INTVAL is_int_type, const char *
prefix)
 {
-    int i;
-    int len = strlen(buf);
+    UINTVAL i;
+    UINTVAL len = strlen(buf);

     if(is_int_type) {
         /* + */
@@ -209,7 +211,7 @@
     else {
         /* string precision */
         if(info->flags & FLAG_PREC && info->prec < len) {
-            buf[info->prec+1]='\0';
+            buf[info->prec]='\0';
             len = info->prec;
         }
     }
@@ -612,8 +614,8 @@
                             break;

                         case 'p':
-                            chptr = va_arg(*args, void *);
-                            int_to_str(t1, t2, (HUGEINTVAL)chptr, 16);
+                            chptr = va_arg(args, void *);
+                            int_to_str(t1, t2,
(HUGEINTVAL)(size_t)chptr, 16);

                             handle_flags(&info, t1, 1, "0x");

@@ -644,7 +646,7 @@
                                 chptr = va_arg(args, char *);

                                 if(!chptr) {
-                                    chptr="";
+                                    chptr=(char*)"";
                                 }

                                 if(strlen(chptr) <
PARROT_SPRINTF_BUFFER_SIZE)
{
@@ -689,7 +691,9 @@
                                 */
                                 string_grow(interpreter, string,
info.width + info.prec + 1);

-                                handle_flags(&info,
(char*)string_to_cstring(interpreter, string), 0, NULL);
+
chptr=(char*)string_to_cstring(interpreter, string);
+
+                                handle_flags(&info, chptr, 0, NULL);
                                 targ = string_concat(interpreter, targ,
string, 0);
                             }
                             break;

--Brent Dax <[EMAIL PROTECTED]>
@roles=map {"Parrot $_"} qw(embedding regexen Configure)

Wire telegraph is a kind of a very, very long cat. You pull his tail in
New York and his head is meowing in Los Angeles. And radio operates
exactly the same way. The only difference is that there is no cat.
    --Albert Einstein (explaining radio)

Reply via email to