Diff
Not logged in

Differences From Artifact [24f6714b9f]:

To Artifact [d138bcdb56]:


734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776

777
778
779
780
781
782
783
784

    if ((BYTEARRAY_MAX_LEN - byteArrayPtr->used) < len) {
	/* Will wrap around !! */
	Tcl_Panic("max size of a byte array exceeded");
    }
    needed = byteArrayPtr->used + len;
    if (needed > byteArrayPtr->allocated) {
	ByteArray *ptr = NULL;

        /*
	 * Try to allocate double the total space that is needed.
	 */

	Tcl_Size attempt;

	/* Make sure we do not wrap when doubling */
	if (needed <= (BYTEARRAY_MAX_LEN - needed)) {
	    attempt = 2 * needed;
	    ptr = (ByteArray *) Tcl_AttemptRealloc(byteArrayPtr,
		    BYTEARRAY_SIZE(attempt));
	}

	if (ptr == NULL) {
	    /*
	     * Try to allocate double the increment that is needed.
	     * (Originally TCL_MIN_GROWTH was added as well but that would
	     * need one more separate overflow check so forget it.)
	     */
	    if (len <= (BYTEARRAY_MAX_LEN - needed)) {
		attempt = needed + len;
		ptr = (ByteArray *)Tcl_AttemptRealloc(byteArrayPtr,
						      BYTEARRAY_SIZE(attempt));
	    }
	}
	if (ptr == NULL) {
	    /*
	     * Last chance: Try to allocate exactly what is needed.
	     */

	    attempt = needed;
	    ptr = (ByteArray *)Tcl_Realloc(byteArrayPtr, BYTEARRAY_SIZE(attempt));
	}
	byteArrayPtr = ptr;

	byteArrayPtr->allocated = attempt;
	SET_BYTEARRAY(irPtr, byteArrayPtr);
    }

    if (bytes) {
	memcpy(byteArrayPtr->bytes + byteArrayPtr->used, bytes, len);
    }
    byteArrayPtr->used += len;







<
<
<
<
<
<
|
<
<
<
<
|
<
<
|
<
<
<
<
<
<
<
|
<
<
<
<
<
<
<
<
|
<
<
<
|
>
|







734
735
736
737
738
739
740






741




742


743







744








745



746
747
748
749
750
751
752
753
754
755

    if ((BYTEARRAY_MAX_LEN - byteArrayPtr->used) < len) {
	/* Will wrap around !! */
	Tcl_Panic("max size of a byte array exceeded");
    }
    needed = byteArrayPtr->used + len;
    if (needed > byteArrayPtr->allocated) {






	Tcl_Size newCapacity;




	byteArrayPtr =


	    (ByteArray *)TclReallocElemsEx(byteArrayPtr,







					   needed,








					   1,



					   offsetof(ByteArray, bytes),
					   &newCapacity);
	byteArrayPtr->allocated = newCapacity;
	SET_BYTEARRAY(irPtr, byteArrayPtr);
    }

    if (bytes) {
	memcpy(byteArrayPtr->bytes + byteArrayPtr->used, bytes, len);
    }
    byteArrayPtr->used += len;