Questions tagged [unsafe-pointers]

Some "safe" languages like Swift and Go offer "unsafe" pointers for use with APIs written in languages like C and Objective-C. Questions using this tag should also have the relevant language tag, e.g. [swift] or [go].

250 questions
-1
votes
2 answers

Copy slice with reflect and unsafe package

I understand that usage of unsafe package of golang is unsafe, but I'm doing it only for education purposes. The idea is to copy a slice field of structure, copy it with reflect package and unsafe.pointer, modify and replace the original slice with…
Paul
  • 6,641
  • 8
  • 41
  • 56
-1
votes
1 answer

Hex string to UnsafePointer swift

I am looking a better way to convert a hex string to an array of UnsafePointer. here is my current code: let pointer: UnsafePointer? = NSString(string: "d0c6a560de2e60b6ac55386defefdf93b0c907290c2ad1b4dbd3338186bfdc68").utf8String // or let…
Payam Khaninejad
  • 7,692
  • 6
  • 45
  • 55
-1
votes
1 answer

Create CGImage from Data multiple times results with previous image override

When generating a CGImage one can choose between an initializer using JPEG-encoded data, PNG-encoded data or just data. I'm generating an image from a Data object containing 16 bit grayscale values. The initializer required a CGDataProvider which…
Yonatan Vainer
  • 453
  • 5
  • 15
-1
votes
1 answer

Strange behavior of UnsafeMutablePointer

I've built a little structure which holds a pseudo-C-String UnsafeMutablePointer. Now I wanted to add a way to get the length of the String, but something behaved very strange: struct Char { let value: CChar init(_ char: CChar) { …
Josef Zoller
  • 921
  • 2
  • 8
  • 24
-1
votes
1 answer

Copy Int to UnsafeMutablePointer

I have an Int which I want to copy to a pointer of type UnsafeMutablePointer? I tried to cast it to Data and then copy it, but the copy function param is of type UnsafeMutablePointer This is what I've tried: var sizePointer:…
Witterquick
  • 6,048
  • 3
  • 26
  • 50
-1
votes
1 answer

How to use UnsafePointer with Swift 3

I am trying to use the function made by Martin R as an answer to this question: Get terminal output after a command swift However, the UnsafePointer line no longer works with Swift 3 and I'm having trouble figuring it out. How would I adapt this…
Narwhal
  • 744
  • 1
  • 8
  • 22
-1
votes
3 answers

system crash after declaring global object of the class

I am very new to c++. I am getting system crash (not compilation error) in doing following: I am declaring global pointer of class. BGiftConfigFile *bgiftConfig; class BGiftConfigFile : public EftBarclaysGiftConfig { } in this class I am reading…
coming out of void
  • 1,454
  • 2
  • 12
  • 12
-2
votes
2 answers

How to convert VB.net unsafe pointers?

How to transfer this code from C# to VB.net? This is from C# if (local > 0) { //Local patches set offsets to data located elsewhere in this section IntPtr start = data + section->_localPatchesOffset; LocalPatch* patch =…
John76
  • 1
  • 2
-2
votes
1 answer

i dont get the unsafe pointer in swift

i use an api in swift that provide me a function to send data to some destination ,the function has a parameter of type UnsafeMutablePointer < astruct >. astruct is a structure and has three variable, first one is the data , that is of type…
-4
votes
1 answer

Is "unsafe.Pointer(&x)" unsafe to call?

I am working on a project in Go. I used "unsafe.Pointer(&x)" and while checking with some bug checker and vulnerability checker program, I am getting this warning that I should avoid using this. So I want to know is it really a vulnerability or how…
Subhash Rawat
  • 451
  • 6
  • 13
1 2 3
16
17