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 7980837
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T10:11:29+00:00 2026-06-04T10:11:29+00:00

We have got a function with 3 static variables. It is weird but we

  • 0

We have got a function with 3 static variables. It is weird but we see sometimes one of the 3 static variables is getting reinitialized:

static uchar * Foo( uchar c_par1, uchar c_par2, uchar c_par3 )
{
   static char        s_var1[10];
   static uchar       c_var2     = 0;
   static uchar       c_var3     = 0;
   .....
   return s_var1;
}

In the above case c_var2 is getting reinitailized sometimes.

We are sure it is reinitailized because we are also printing the memory location of each of these variables and it is never changed. We suspected s_var1 might overwrite the c_var2 but the memory locations of these 2 variables are far apart.

  • 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-04T10:11:31+00:00Added an answer on June 4, 2026 at 10:11 am

    We suspected s_var1 might overwrite the c_var2 but the memory locations of these 2 variables are far apart.

    This sounds like a global buffer overflow somewhere.

    Run nm -n a.out, and find out what variables are near c_var2. Then look for overflows caused by these variables.

    Or use Address Sanitizer, which should be able to give you exact location of the bug quite easily.

    Another way to debug this: run the program under GDB, and set a watchpoint on the address of c_var2. The watchpoint should fire every time c_var2 is modified.

    For intance if i add delay somewhere

    If your program is multithreaded, then note that static variables and threads don’t work together well.

    If it is not multithreaded, I don’t see how a delay could have any effect (unless you are also processing signals).

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

Sidebar

Related Questions

In one of my classes, I have got code: private static void Notify(string url,
I have got a C function in a static library, let's call it A,
I have got this function: public static function insert_user($user) { $con = mysql_connect(localhost,root,) or
I have got a problem with calling a global function, which takes a pointer
I have got the following very simple code: function init() { var articleTabs =
I have got the following issue, my function appends code to a string $string
I have got code like this var challegneListener; $(document).ready(function(){ var challegneListener = setInterval(challengeListenerBot(),5000); });
Code is not running on .click when I have this: $(.cancel).click(function() { alert(got here);
I have got a field that has been setup to allow for Null, but
I have been puzzled by this weird problem and it got me stuck. Please

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.