ya_hossein's blog

By ya_hossein, history, 6 months ago, In English,

بسم الله الرحمن الرحیم

in here i get wrong answer but what is interesting is that logically it's correct but at the end of line it couts another thing...

can anybody says what is wrong?

Diagnostics Diagnostics detected issues [cpp.g++17-drmemory]: ~.M~~ Dr. Memory version 1.11.0 ~.M~~ Running "program.exe"

This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information. ~.M~~ ~.M~~ NO ERRORS FOUND: ~.M~~ 0 unique, 0 total unaddressable access(es) ~.M~~ 0 unique, 0 total uninitialized access(es) ~.M~~ 0 unique, 0 total invalid heap argument(s) ~.M~~ 0 unique, 0 total GDI usage error(s) ~.M~~ 0 unique, 0 total handle leak(s) ~.M~~ 0 unique, 0 total warning(s) ~.M~~ 0 unique, 0 total, 0 byte(s) of leak(s) ~.M~~ 0 unique, 0 total, 0 byte(s) of possible leak(s) ~.M~~ ERRORS IGNORED: ~.M~~ 2 potential error(s) (suspected false positives) ~.M~~ (details: C:\Programs\drmemory\drmemory\logs\DrMemory-program.exe.5784.002\potential_errors.txt) ~.M~~ 9 unique, 9 total, 23420 byte(s) of still-reachable allocation(s) ~.M~~ (re-run with "-show_reachable" for details) ~.M~~ Details: C:\Programs\drmemory\drmemory\logs\DrMemory-program.exe.5784.002\results.txt ~.M~~ WARNING: application exited with abnormal code 0x3

 
 
 
 
  • Vote: I like it  
  • -23
  • Vote: I do not like it  

»
6 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by ya_hossein (previous revision, new revision, compare).

»
6 months ago, # |
  Vote: I like it +2 Vote: I do not like it

Well. Well. Well.

You can't do this "a[a.size()] = '\0'"

Instead you should do this

"char tmp='\0';

a=a+tmp"

»
6 months ago, # |
  Vote: I like it 0 Vote: I do not like it

it seems that the sign rejected by the CF checker...

on the IDE but it doesn't on the custom test (don't know how ! ).

anyway , your code crashes on the IDE ... you are trying to access an index out of the size of the string a ... the entire loop for(int j = i; j < i + 3; j++) doesn't ensure it is works in the valid range.

  • »
    »
    6 months ago, # ^ |
      Vote: I like it +3 Vote: I do not like it

    It does!!!!!!!!!!!!!!!! Check my submission.

    • »
      »
      »
      6 months ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      thank so much

      it seems that problem is a[a.size()] = '\0'

      but why does it prints another thing while i iterate my loop up to null point.

    • »
      »
      »
      6 months ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      well ! actually the code above and Specifically in the line

      for (int j = i; j < i + 3; j++)

      was out of range by 2 indices (a clear offside :D )

      but METSUKA made a little change , you added a '\0' to the string ,

      BUT the above line still out of the range by 2 !

      the reason why this works that the compiler let you access 2 extra indices when you add the NULL character '\0' to the string.

      try this :


      string s;

      cin>>s;

      s+='\0';


      if the string s = "ABC" , and then you added the NULL => the size will be 4 and you can access the indices {0 , 1 , 2 , 3 ,4} without out_of_range Exception! , and the extra indices will be empty.

      and here is the example