@@ -311,14 +311,11 @@ static bool readPointerToBuffer(const Context &Ctx, const Pointer &FromPtr,
311311 unsigned ValueReprBytes = Val.valueReprBytes (ASTCtx);
312312 assert (ObjectReprBytes >= ValueReprBytes);
313313
314- std::byte *Buff =
315- (std::byte *)std::malloc (ObjectReprChars.getQuantity ());
316- Val.bitcastToMemory (Buff);
317-
314+ llvm::SmallVector<std::byte> Buff (ObjectReprChars.getQuantity ());
315+ Val.bitcastToMemory (Buff.data ());
318316 if (BigEndian)
319- swapBytes (Buff, BitWidth / 8 );
320- Bits.pushData (Buff, BitOffset, BitWidth);
321- std::free (Buff);
317+ swapBytes (Buff.data (), BitWidth / 8 );
318+ Bits.pushData (Buff.data (), BitOffset, BitWidth);
322319 });
323320 return true ;
324321 });
@@ -386,17 +383,16 @@ bool DoBitCastToPtr(InterpState &S, const Pointer &P, Pointer &DestPtr,
386383 const auto &Sem = ASTCtx.getFloatTypeSemantics (FloatType);
387384
388385 CharUnits ObjectReprChars = ASTCtx.getTypeSizeInChars (P.getType ());
389- const std::byte *M = Bytes. getBytes (BitOffset, 1234 );
390- std::byte *Buff =
391- (std::byte *) std::malloc ( ObjectReprChars.getQuantity ());
392- std::memcpy (Buff, M, ObjectReprChars.getQuantity ());
386+ llvm::SmallVector< std::byte> Buff (ObjectReprChars. getQuantity () );
387+ const std::byte *M =
388+ Bytes. getBytes (BitOffset, ObjectReprChars.getQuantity ());
389+ std::memcpy (Buff. data () , M, ObjectReprChars.getQuantity ());
393390
394391 if (BigEndian)
395- swapBytes (Buff, ObjectReprChars.getQuantity ());
392+ swapBytes (Buff. data () , ObjectReprChars.getQuantity ());
396393
397- P.deref <Floating>() = Floating::bitcastFromMemory (Buff, Sem);
394+ P.deref <Floating>() = Floating::bitcastFromMemory (Buff. data () , Sem);
398395 P.initialize ();
399- std::free (Buff);
400396 return true ;
401397 }
402398 if (T == PT_Ptr) {
@@ -435,16 +431,14 @@ bool DoBitCastToPtr(InterpState &S, const Pointer &P, Pointer &DestPtr,
435431
436432 assert (!P.getField ()->isBitField ());
437433
438- std::byte *Copy = ( std::byte *) std::malloc (ValueReprBits / 8 );
439- const std::byte *M = Bytes.getBytes (BitOffset, 1234 );
434+ llvm::SmallVector< std::byte> Copy (ValueReprBits / 8 );
435+ const std::byte *M = Bytes.getBytes (BitOffset, ValueReprBits / 8 );
440436
441- std::memcpy (Copy, M, ValueReprBits / 8 );
437+ std::memcpy (Copy. data () , M, ValueReprBits / 8 );
442438
443- if (BigEndian) {
444- swapBytes (Copy, ValueReprBits / 8 );
445- }
446- Val = T::bitcastFromMemory (Copy, Val.bitWidth ());
447- std::free (Copy);
439+ if (BigEndian)
440+ swapBytes (Copy.data (), ValueReprBits / 8 );
441+ Val = T::bitcastFromMemory (Copy.data (), Val.bitWidth ());
448442
449443 if (!HasIndeterminateBits)
450444 P.initialize ();
0 commit comments