Diff
Not logged in

Differences From Artifact [24819013e5]:

To Artifact [2da4e211fa]:


179
180
181
182
183
184
185


186

187
188
189
190
191
192
193
179
180
181
182
183
184
185
186
187

188
189
190
191
192
193
194
195







+
+
-
+







				 * minus 1 byte. */
    unsigned char bytes[TCLFLEXARRAY];	/* The array of bytes. The actual size of this
				 * field depends on the 'allocated' field
				 * above. */
} ByteArray;

#define BYTEARRAY_SIZE(len) \
	( (offsetof(ByteArray, bytes) + (len) < offsetof(ByteArray, bytes)) \
	? (Tcl_Panic("max size of a Tcl value exceeded"), 0) \
		(offsetof(ByteArray, bytes) + (len))
	: (offsetof(ByteArray, bytes) + (len)) )
#define GET_BYTEARRAY(irPtr) ((ByteArray *) (irPtr)->twoPtrValue.ptr1)
#define SET_BYTEARRAY(irPtr, baPtr) \
		(irPtr)->twoPtrValue.ptr1 = (baPtr)

int
TclIsPureByteArray(
    Tcl_Obj * objPtr)
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801





802
803
804
805
806
807
808
809



810
811
812






813
814
815
816
817
818
819

820



821
822
823
824
825
826
827
783
784
785
786
787
788
789










790
791
792
793
794
795
796
797
798
799
800

801




802
803
804
805


806
807
808
809
810
811
812
813
814
815
816
817
818
819

820
821
822
823
824
825
826
827
828
829







-
-
-
-
-
-
-
-
-
-




+
+
+
+
+


-

-
-
-
-
+
+
+

-
-
+
+
+
+
+
+







+
-
+
+
+







	if (TCL_ERROR == SetByteArrayFromAny(NULL, TCL_INDEX_NONE, objPtr)) {
	    Tcl_Panic("attempt to append bytes to non-bytearray");
	}
	irPtr = TclFetchInternalRep(objPtr, &properByteArrayType);
    }
    byteArrayPtr = GET_BYTEARRAY(irPtr);

    /* Size limit check now commented out.  Used to protect calls to
     * Tcl_*Alloc*() limited by unsigned int arguments.
     *
    if (len > UINT_MAX - byteArrayPtr->used) {
	Tcl_Panic("max size for a Tcl value (%u bytes) exceeded", UINT_MAX);
    }
     *
     */

    needed = byteArrayPtr->used + len;
    /*
     * If we need to, resize the allocated space in the byte array.
     */

    needed = byteArrayPtr->used + len;
    if (needed < byteArrayPtr->used) {
	/* Wrapped around SIZE_MAX!! */
	Tcl_Panic("max size of a Tcl value exceeded");
    }
    if (needed > byteArrayPtr->allocated) {
	ByteArray *ptr = NULL;
	size_t attempt;

	if (needed <= INT_MAX/2) {
	    /*
	     * Try to allocate double the total space that is needed.
	     */
        /*
	 * Try to allocate double the total space that is needed.
	 */

	    attempt = 2 * needed;
	    ptr = (ByteArray *)Tcl_AttemptRealloc(byteArrayPtr, BYTEARRAY_SIZE(attempt));
	size_t attempt = 2 * needed;

	/* Protection just in case we wrapped around SIZE_MAX */
	if (attempt >= needed) {
	    ptr = (ByteArray *) Tcl_AttemptRealloc(byteArrayPtr,
		    BYTEARRAY_SIZE(attempt));
	}
	if (ptr == NULL) {
	    /*
	     * Try to allocate double the increment that is needed (plus).
	     */

	    attempt = needed + len + TCL_MIN_GROWTH;
	    if (attempt >= needed) {
	    ptr = (ByteArray *)Tcl_AttemptRealloc(byteArrayPtr, BYTEARRAY_SIZE(attempt));
		ptr = (ByteArray *) Tcl_AttemptRealloc(byteArrayPtr,
			BYTEARRAY_SIZE(attempt));
	    }
	}
	if (ptr == NULL) {
	    /*
	     * Last chance: Try to allocate exactly what is needed.
	     */

	    attempt = needed;