@@ -311,14 +311,11 @@ static bool readPointerToBuffer(const Context &Ctx, const Pointer &FromPtr,
311
311
unsigned ValueReprBytes = Val.valueReprBytes (ASTCtx);
312
312
assert (ObjectReprBytes >= ValueReprBytes);
313
313
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 ());
318
316
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);
322
319
});
323
320
return true ;
324
321
});
@@ -386,17 +383,16 @@ bool DoBitCastToPtr(InterpState &S, const Pointer &P, Pointer &DestPtr,
386
383
const auto &Sem = ASTCtx.getFloatTypeSemantics (FloatType);
387
384
388
385
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 ());
393
390
394
391
if (BigEndian)
395
- swapBytes (Buff, ObjectReprChars.getQuantity ());
392
+ swapBytes (Buff. data () , ObjectReprChars.getQuantity ());
396
393
397
- P.deref <Floating>() = Floating::bitcastFromMemory (Buff, Sem);
394
+ P.deref <Floating>() = Floating::bitcastFromMemory (Buff. data () , Sem);
398
395
P.initialize ();
399
- std::free (Buff);
400
396
return true ;
401
397
}
402
398
if (T == PT_Ptr) {
@@ -435,16 +431,14 @@ bool DoBitCastToPtr(InterpState &S, const Pointer &P, Pointer &DestPtr,
435
431
436
432
assert (!P.getField ()->isBitField ());
437
433
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 );
440
436
441
- std::memcpy (Copy, M, ValueReprBits / 8 );
437
+ std::memcpy (Copy. data () , M, ValueReprBits / 8 );
442
438
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 ());
448
442
449
443
if (!HasIndeterminateBits)
450
444
P.initialize ();
0 commit comments