Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8817873
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:57:28+00:00 2026-06-14T04:57:28+00:00

I am trying get a handle on C and Cyclone as I work my

  • 0

I am trying get a handle on C and Cyclone as I work my way thru Jim Trevor’s “Cyclone: A safe dialect of C” for a PL class. Trevor gives this example of an unsafe go-to statement:

int z;
{ int x = 0xBAD; goto L; }
{ int *y = &z;
L: *y = 3; // Possible segfault
}

Trevor explains the safety issue in the above code as follows:

Many compilers stack allocate
the local variables of a block when it is entered, and
deallocate (pop) the storage when the block exits
(though this is not mandated by the C standard).
If the example is compiled in this way, then when
the program enters the first block, space for x is allocated on the stack, and is initialized with the value
0xBAD. The goto jumps into the middle of the second block, directly to the assignment to the contents
of the pointer y. Since y is the first (only) variable
declared in the second block, the assignment expects
y to be at the top of the stack. Unfortunately, that’s
exactly where x was allocated, so the program tries
to write to location 0xBAD, probably triggering a
segmentation fault.

I don’t understand why the go to statement is an issue here. It seems like the issue is unpredictable behavior from the un-initialized pointer Z. At the start of the second block, int * y be filled with the address of Z. Z is uninitialized so it would fill int* y with the bit pattern on the stack in the area of memory referenced by Z. I don’t understand why Trevor’s paper implies that Z and X somehow both reference 0xBAD. Wouldn’t C create a new stack frame for the first block (as Trevor describes): thus writing 0xBAD to a new frame in memory (and not the location in memory referenced by Z)?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T04:57:29+00:00Added an answer on June 14, 2026 at 4:57 am

    I don’t understand why the go to statement is an issue here.

    goto L bypasses the initialization of y (y will not be set to &z), hence the problem when assigning to who-knows-where-it’s-pointing *y.

    It seems like the issue is unpredictable behavior from the
    un-initialized pointer Z

    No. The pointer &z is actually valid. The int value z is uninitialized, but that does not matter since you never attempt to read it; you’re actually trying to overwrite it.

    At the start of the second block, int * y be filled with the address of Z.

    That is the point. goto L bypasses that.

    I don’t understand why Trevor’s paper implies that Z and X somehow both reference 0xBAD

    I think Trevor is implying a second potential problem here, though I’m not sure how many compilers, if any, would actually exhibit it. When leaving the block with goto, the stack pointer (e.g. ESP on x86) may theoretically not be decremented. By skipping the initialization of y, the stack pointer may not be incremented either. So if the compiler refers to locals using the stack pointer (instead of a frame pointer, e.g. EBP on x86), such a compiler may theoretically mistake x for y, as if int* y = 0xBAD had happened.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying get a handle on C as I work my way thru
Trying to get a handle on the FTP library in Python. :) Got this
I'm trying to get a handle on this whole Ant buildsystem thing. I've created
Trying to get a handle on how these things work. If I register an
I'm trying to get the process handle of, say example.exe, so I can call
Is there any documentation on this? I'm trying to get a handle on the
I'm trying to get a better handle on using sockets asynchronously. According to this
I am trying to get the handle of a window from a process. Now,
I'm trying to get a handle on whether we have a problem in our
I am trying to get a handle on Solrnet and interacting an ASP.NET site

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.