Modify the value of a variable while the program is running under Linux

Source: Internet
Author: User

1 #include <stdio.h>

2 #include <stdlib.h>

3

4 void Bug ()

5 {

6 System ("reboot");

7 exit (0);

8}

9 int stack_test (int a,int b)

10 {

//int *p=&a;

//p--;

//*p=bug;

printf ("Before write:0x%x\n", b);

*p=&a; int

p++;

*P=0XDDDD;

printf ("After write:0x%x\n", b);

C=0XCCCC int;

return C;

21}

int main ()

23 {

A=0XAAAA int;

B=0XBBBB int;

Ret=stack_test Int (A, b);

printf ("You should run here\n");

return 0;

29}


The result of the program operation is:

Before WRITE:0XBBBB

After WRITE:0XDDDD

Should run here

The bug function restarts the system;

The reason for the change in the value of B: function parameters in the stack when the right-to-left, so B on the next A on, the pointer p to a, p at + + point to the B, so change the value of the pointer p will change the value of B


This article is from the "fringe" blog, so be sure to keep this source http://ab6107.blog.51cto.com/10538332/1761446

Modify the value of a variable while the program is running under Linux

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.