commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r895961 - /commons/sandbox/runtime/trunk/src/main/native/shared/sbuf.c
Date Tue, 05 Jan 2010 09:38:38 GMT
Author: mturk
Date: Tue Jan  5 09:38:37 2010
New Revision: 895961

URL: http://svn.apache.org/viewvc?rev=895961&view=rev
Log:
Guard against uninited sbuf

Modified:
    commons/sandbox/runtime/trunk/src/main/native/shared/sbuf.c

Modified: commons/sandbox/runtime/trunk/src/main/native/shared/sbuf.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/sbuf.c?rev=895961&r1=895960&r2=895961&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/sbuf.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/sbuf.c Tue Jan  5 09:38:37 2010
@@ -55,9 +55,9 @@
 #define SBUF_ISDYNAMIC(s)       ((s)->s_flags & ACR_SBUF_DYNAMIC)
 #define SBUF_ISDYNSTRUCT(s)     ((s)->s_flags & ACR_SBUF_DYNSTRUCT)
 #define SBUF_ISFINISHED(s)      ((s)->s_flags & ACR_SBUF_FINISHED)
-#define SBUF_HASOVERFLOWED(s)   ((s)->s_flags & ACR_SBUF_OVERFLOWED)
-#define SBUF_HASROOM(s)         ((s)->s_len  < (s)->s_size - 1)
-#define SBUF_FREESPACE(s)       ((s)->s_size - (s)->s_len  - 1)
+#define SBUF_HASOVERFLOWED(s)   ((s)->s_flags & ACR_SBUF_OVERFLOWED || (s)->s_buf
== NULL)
+#define SBUF_HASROOM(s)         ((s)->s_len   < ((s)->s_size - 1))
+#define SBUF_FREESPACE(s)       ((s)->s_size  - ((s)->s_len  - 1))
 #define SBUF_CANEXTEND(s)       ((s)->s_flags & ACR_SBUF_AUTOEXTEND)
 
 /*
@@ -405,6 +405,8 @@
 {
 
     char *p = s->s_buf;
+    if (SBUF_HASOVERFLOWED(s))
+        return NULL;
 
     acr_sbuf_rtrim(s);
     acr_sbuf_finish(s);
@@ -431,10 +433,10 @@
 void
 acr_sbuf_finish(acr_sbuf_t *s)
 {
-
-    s->s_buf[s->s_len] = '\0';
-
-    SBUF_CLRFLAG(s, ACR_SBUF_OVERFLOWED);
+    if (s->s_buf) {
+        s->s_buf[s->s_len] = '\0';
+        SBUF_CLRFLAG(s, ACR_SBUF_OVERFLOWED);
+    }
     SBUF_SETFLAG(s, ACR_SBUF_FINISHED);
 }
 
@@ -772,10 +774,11 @@
 void
 acr_wbuf_finish(acr_wbuf_t *s)
 {
+    if (s->s_buf) {
+        s->s_buf[s->s_len] = L'\0';
 
-    s->s_buf[s->s_len] = L'\0';
-
-    SBUF_CLRFLAG(s, ACR_SBUF_OVERFLOWED);
+        SBUF_CLRFLAG(s, ACR_SBUF_OVERFLOWED);
+    }
     SBUF_SETFLAG(s, ACR_SBUF_FINISHED);
 }
 



Mime
View raw message