Home > Software engineering >  Using cstrings strange problems
Using cstrings strange problems

Time:09-21

A class a members below several cstrings
A.s tr1
A.s tr2
A.s tr3
.
.
.
Then the members of the value will be changed in BBB () a function
Such as become
A.s tr1="1"
A.s tr2="2"
A.s tr3="3"
.
.
.
However, when the BBB () after completion of execution and returns on a layer of calling a function (pay attention to the track to the front of the return of BBB, these values are normal), all these values reach a into a
A.s tr1="2"
A.s tr2="3"
A.s tr3="4"
.
.
.
A.s TRN="mouth"

Last a.s TRN was supposed to be "n", has become a "mouth" of the code
Excuse me what reason, how should solve?

CodePudding user response:

Depending on the code

CodePudding user response:

Code is released, there is no code is a smart fantasies

CodePudding user response:

Let's track to see where is in modify the value of the string

CodePudding user response:

If there are any other places damaged data

CodePudding user response:

Before returning, set data breakpoint debugging operation

CodePudding user response:

Fyi:
 # include & lt; time.h> 
# include & lt; Stdlib. H>
# include & lt; Windows. H>
Int main () {
Int a, b [11].//was b [10], to decide which words of cross-border, intentionally statement for b [11]

Srand ((unsigned int) time (NULL));//press F11 twice, such as yellow right arrow pointing to the bank, the debugging, the new breakpoint, new data breakpoints, address: & amp; B [10], byte count: 4, sure,
While (1) {//press F5, will stop in the following sentence, as a value of 10, b has been modified to corresponding to 0. [10]. One of the four,
B (11) (a=rand () %]=0;
Sleep (100);
B (11) (a=rand () %]=1;
Sleep (100);
B (11) (a=rand () %]=2;
Sleep (100);
B (11) (a=rand () %]=3;
Sleep (100);
B (11) (a=rand () %]=4;
Sleep (100);
}
return 0;
}

CodePudding user response:

Suggest debug step by step, looking is what reason causes forward

CodePudding user response:

Single pace, affirmation is to program has a problem, so there is nothing wrong with using cstrings

CodePudding user response:

Can't see the code is bullshit

CodePudding user response:

The parameters of the function of BBB is a class a? Or other strong??

CodePudding user response:

QQ I

CodePudding user response:

Breakpoint debugging, it can't be coding problem, cstrings with such right

CodePudding user response:

Debugging data values puzzling change this kind of problem, please use the # 7 recommended by using the method of data breakpoints

CodePudding user response:

This play should step to check, must be written code problem,

CodePudding user response:

Estimation procedure where the errors senior

CodePudding user response:

The problem of good magic,

CodePudding user response:

1 you may have outdated PDB file, cause debugging display an error (if the program runs it is normal)
2 BBB has the damage ebp, return address errors, the first step should be added in compiling parameters/GS compile and add # pragma strict_gs_check (on), some static code analysis tools can also help you to find out the problems (such as Visual c + + compiler options/analyze),

CodePudding user response:

Consider a simple way to give it a try: remove temporary files in the project, etc, and then compile the program again and then run and have a look

CodePudding user response:

The
refer to the original poster shanyang1 response:
a class a member of several cstrings below
A.s tr1
A.s tr2
A.s tr3
.
.
.
Then the members of the value will be changed in BBB () a function
Such as become
A.s tr1="1"
A.s tr2="2"
A.s tr3="3"
.
.
.
However, when the BBB () after completion of execution and returns on a layer of calling a function (pay attention to the track to the front of the return of BBB, these values are normal), all these values reach a into a
A.s tr1="2"
A.s tr2="3"
A.s tr3="4"
.
.
.
A.s TRN="mouth"

Last a.s TRN was supposed to be "n", has become a "mouth" of the code
Excuse me what reason, how should solve?



Memory overflow??

CodePudding user response:

Is the total the BBB change the string

CodePudding user response:

First of all, according to your provide
A.s tr1="2"
A.s tr2="3"
A.s tr3="4"
.
.
.
A.s TRN="mouth"
Forward to see it ought to be you at the time of data operation is similar to the array subscript starting from 0, you're starting from 1, the final data is "mouth" is your cross-border data read operation

CodePudding user response:

What is the relationship between str1 str2 str3?

CodePudding user response:

Slowly step debug

CodePudding user response:

Obviously is a code problem, to debug the debugging,

CodePudding user response:

Generally have the code, because no terminators after string, such as 0 or null

CodePudding user response:

reference 24th floor songyachao response:
first according to your provide
A.s tr1="2"
A.s tr2="3"
A.s tr3="4"
.
.
.
A.s TRN="mouth"
Forward to see it ought to be you at the time of data operation is similar to the array subscript starting from 0, you're starting from 1, the last data is "mouth" is your cross-border operation data read

CodePudding user response:

BBBB before the function returns to normal, return values change, the best in the debug test when check memory changes
  • Related