Questions tagged [unsafe]

In C# or Rust, the unsafe keyword marks code able to work directly with memory pointers, bypassing some of the language's safety checks. In Java, `sun.misc.Unsafe` is a special class performing low-level, unsafe operations.

In C# The unsafe keyword denotes an unsafe context, which is required for any operation involving pointers. You can use the unsafe modifier in the declaration of a type or a member. Once so declared, the entire textual extent of the type or member is considered an unsafe context.

For more information, see Unsafe Code and Pointers (C# Programming Guide)

The unsafe Keyword on MSDN
http://msdn.microsoft.com/en-us/library/chfa2zb8(v=vs.100).aspx


In Java, sun.misc.Unsafe is a special class performing low-level, unsafe operations. Though this is a private platform API, this class is used extensively in many projects and libraries including Hadoop, Spark, Guava, Cassandra, etc.


In Rust, the unsafe keyword denotes a function or block that is implemented outside some of the safeguards of the compiler. Thus it is as much an escape hatch as a device to easily document code that might require increased attention. More information can be found in the Rust Book


In Go, package unsafe contains operations that step around the type safety of Go programs. Packages that import unsafe may be non-portable and are not protected by the Go 1 compatibility guidelines.

990 questions
0
votes
0 answers

meaning of allow unsafe code in VS2013

i need to understand, what is meant by allow unsafe code? and there is safe and unsafe code ?
0
votes
1 answer

Have two class members point to the same memory address

I want to have two value-type members of my class point to the same memory address, so that initializing one would initialize the other and changing one would change the other. Alternatively it could be two variables within a function, or, a way to…
NeatNit
  • 526
  • 1
  • 4
  • 14
0
votes
1 answer

Why Unsafe.allocateInstance(Class.class) failed?

I'm now using unsafe. When I run the following code: unsafe.allocateInstance(Class.class) There happen's Exception in thread "main" java.lang.IllegalAccessException: java.lang.Class Since Class is a non-abstract class, why it so special? And is…
Dean Xu
  • 4,438
  • 1
  • 17
  • 44
0
votes
0 answers

Memory allocation and address in Java

I'm trying to turn off GC and manage memory by hand in hot pieces of code. Here is what I'm trying to do: private static Unsafe unsafe = getUnsafe(); //... long ptr = unsafe.allocateMemory(3); String s = "abc"; byte[] bts = s.getBytes(); …
St.Antario
  • 26,175
  • 41
  • 130
  • 318
0
votes
1 answer

ionic 2 : Getting unsafe url error

I'm trying to open a whats'app link and I'm getting thus error : WARNING: sanitizing unsafe URL value SafeValue must use (see http://g.co/ng/security#xss) here is my code :
keloa zoldik
  • 95
  • 1
  • 15
0
votes
1 answer

C# compile errors in unsafe code

Compiling a VS 2010 c# project (.NET 4.0, any CPU, allow unsafe code = checked) we are getting a variety of compile errors as below: Operator '*' cannot be applied to operands of type 'System.IntPtr' and 'int' Constant value '325486741' cannot be…
Munish Goyal
  • 1,379
  • 4
  • 27
  • 49
0
votes
2 answers

call mono_method(pointer) from c

i have mono code public static unsafe int* mono_method (int* p) { //.... return p; } and want to call it from native c MonoObject *result = mono_runtime_invoke(mono_method, NULL, args, NULL); I tried out some different pointers, variables in…
Gobliins
  • 3,848
  • 16
  • 67
  • 122
0
votes
1 answer

fix unsafe variable assignment in case statement

So I know it aint right to assign a variable inside a case statement, but I can't figure out how to refactor this so that the user gets redirected AND the conn gets assigned correctly: case Repo.insert(changeset) do {:ok,user} -> conn =…
MetaStack
  • 3,266
  • 4
  • 30
  • 67
0
votes
0 answers

Java Unsafe Versus DirectByteBuffer

I'm trying to process a file int-wise efficiently. I do this by firstly mapping the file into memory by using a MappedByteBuffer: public static ByteBuffer getByteBuffer(String filePath, int start, long size) throws IOException { File binaryFile…
BullyWiiPlaza
  • 17,329
  • 10
  • 113
  • 185
0
votes
1 answer

No idea why median filter does not work properly

I have problem with median filter implementation in c# for image processing purposes. I have implemented this filter with unsafe locking bits method and the problem is the image which I am receiving is somehow blurred in the horrizontal way (the…
Pawel
  • 162
  • 2
  • 12
0
votes
4 answers

C# convert byte[] to string[]

I am coding in C# and willing to use unsafe/fixed. I would like to be able to convert from a byte[] to a string[]. I started with a file of strings (terminated by \n). I replaced all of the \n with \0 in the byte array that I read from the file. …
docjosh
  • 85
  • 1
  • 1
  • 8
0
votes
3 answers

Is my php codes safe?

Is my php codes safe ?
faressoft
  • 19,053
  • 44
  • 104
  • 146
0
votes
1 answer

MS Access form gets broken after enabling unsafe content

I have a MS Access project, which was developed in MS Access 97. I successfully converted it to MS Access 2016 (that was a long story tho). Everything looks fine, but I have noticed a very strange behavior. When user opens the project file in client…
fakemeta
  • 938
  • 1
  • 8
  • 21
0
votes
1 answer

Changing a readonly string field

Why can I do this? Is it a bug? Debug.WriteLine (System.Boolean.FalseString); // output: "False" fixed (char* xx = System.Boolean.FalseString) { xx[1] = 'X'; } Debug.WriteLine (System.Boolean.FalseString); // output: "FXlse" Then, the…
jmmcba
  • 39
  • 3
0
votes
1 answer

Is there a faster way to loop over an array in safe mode

I am writing a method to measure the frequency of a sampled sine wave. It takes a somewhat large 1D array (10^3 to 10^4 samples order of magnitude) and returns a double. A helper methods is also called within the body of the method that checks…
skwear
  • 563
  • 1
  • 5
  • 24