Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Strange chars

Strange chars

Scheduled Pinned Locked Moved C / C++ / MFC
debuggingwindows-adminlinuxquestion
35 Posts 7 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Lost User

    I have just tried to reproduce what you have done and the code works fine. I can only conclude that the code you are showing does not match what you are actually running. But since you have only shown small pieces and not the complete method where this occurs, it is difficult to say more.

    _ Offline
    _ Offline
    _Flaviu
    wrote on last edited by
    #17

    I really, really would show the entire code because I am struggling of it, but unfortunately I cannot due to confidentiality issue. I'll try to write more code here.

    K L D 3 Replies Last reply
    0
    • _ _Flaviu

      I really, really would show the entire code because I am struggling of it, but unfortunately I cannot due to confidentiality issue. I'll try to write more code here.

      K Offline
      K Offline
      kalberts
      wrote on last edited by
      #18

      What you need to display is the assignment to dir_struct.directory - nothing more. It may be as simple as a single statement (/line). I guess that confidentiality issues won't preclude that. How did you get hold of that value? Which system call or library function provided it? If you say "None, we built it from pieces ourselves, and that code is confidential", then you have got the answer: In that string building code you forgot to add the terminating nul. Otherwise: Tell us who provided the directory string, in which way.

      _ 1 Reply Last reply
      0
      • _ _Flaviu

        I really, really would show the entire code because I am struggling of it, but unfortunately I cannot due to confidentiality issue. I'll try to write more code here.

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #19

        I am sure that you can modify any confidential pieces so they do not reveal anything that they should not.

        _ 1 Reply Last reply
        0
        • K kalberts

          What you need to display is the assignment to dir_struct.directory - nothing more. It may be as simple as a single statement (/line). I guess that confidentiality issues won't preclude that. How did you get hold of that value? Which system call or library function provided it? If you say "None, we built it from pieces ourselves, and that code is confidential", then you have got the answer: In that string building code you forgot to add the terminating nul. Otherwise: Tell us who provided the directory string, in which way.

          _ Offline
          _ Offline
          _Flaviu
          wrote on last edited by
          #20

          No, this code is not written by us. I'll try to write here as much as I can. P.S. The buggy code is written in C for Linux, and I don't know C (I guess this is visible :D) P.S. I don't pretend to know C++ either :D ... only that I fight in this domain ....

          1 Reply Last reply
          0
          • L Lost User

            I am sure that you can modify any confidential pieces so they do not reveal anything that they should not.

            _ Offline
            _ Offline
            _Flaviu
            wrote on last edited by
            #21

            info* current = list_entry(walker, const info, list);
            TRACE(_T("current->name %s\n"), current->name); -> _CrtDbgReport: String too long or IO Error

            Why I got _CrtDbgReport: String too long or IO Error I wrote in my previous posts ...

            L 1 Reply Last reply
            0
            • _ _Flaviu

              info* current = list_entry(walker, const info, list);
              TRACE(_T("current->name %s\n"), current->name); -> _CrtDbgReport: String too long or IO Error

              Why I got _CrtDbgReport: String too long or IO Error I wrote in my previous posts ...

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #22

              I have managed to create a sample of all that code, although I find the #define list_entry_const somewhat difficult to deconstruct. However, with a valid name in the file_info entry it works fine. I can only assume that somewhere in the actual code that you are running there is some corruption of your data, or a pointer is not set up correctly. [edit] I also could not find the TRACE macro in Windows. [/edit]

              D V 2 Replies Last reply
              0
              • _ _Flaviu

                I really, really would show the entire code because I am struggling of it, but unfortunately I cannot due to confidentiality issue. I'll try to write more code here.

                D Offline
                D Offline
                David Crow
                wrote on last edited by
                #23

                Like they say in the movies, the names have been changed to protect the innocent.

                "One man's wage rise is another man's price increase." - Harold Wilson

                "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

                _ 1 Reply Last reply
                0
                • L Lost User

                  I have managed to create a sample of all that code, although I find the #define list_entry_const somewhat difficult to deconstruct. However, with a valid name in the file_info entry it works fine. I can only assume that somewhere in the actual code that you are running there is some corruption of your data, or a pointer is not set up correctly. [edit] I also could not find the TRACE macro in Windows. [/edit]

                  D Offline
                  D Offline
                  David Crow
                  wrote on last edited by
                  #24

                  Richard MacCutchan wrote:

                  I also could not find the TRACE macro in Windows.

                  Isn't that an MFC thing?

                  "One man's wage rise is another man's price increase." - Harold Wilson

                  "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                  "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

                  L 1 Reply Last reply
                  0
                  • D David Crow

                    Richard MacCutchan wrote:

                    I also could not find the TRACE macro in Windows.

                    Isn't that an MFC thing?

                    "One man's wage rise is another man's price increase." - Harold Wilson

                    "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                    "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

                    L Offline
                    L Offline
                    Lost User
                    wrote on last edited by
                    #25

                    Could be, but I haven't used MFC since about 2003, and I don't intend doing so ever again.

                    1 Reply Last reply
                    0
                    • L Lost User

                      I have managed to create a sample of all that code, although I find the #define list_entry_const somewhat difficult to deconstruct. However, with a valid name in the file_info entry it works fine. I can only assume that somewhere in the actual code that you are running there is some corruption of your data, or a pointer is not set up correctly. [edit] I also could not find the TRACE macro in Windows. [/edit]

                      V Offline
                      V Offline
                      Victor Nijegorodov
                      wrote on last edited by
                      #26

                      Richard MacCutchan wrote:

                      I also could not find the TRACE macro in Windows.

                      After a lot of calls... it finishes calling _CrtDbgReportW

                      L 1 Reply Last reply
                      0
                      • V Victor Nijegorodov

                        Richard MacCutchan wrote:

                        I also could not find the TRACE macro in Windows.

                        After a lot of calls... it finishes calling _CrtDbgReportW

                        L Offline
                        L Offline
                        Lost User
                        wrote on last edited by
                        #27

                        It's an MFC* macro (as pointed out by David Crow above). *Yes, I know, that combination of letters should no more pass my lips.

                        1 Reply Last reply
                        0
                        • D David Crow

                          Like they say in the movies, the names have been changed to protect the innocent.

                          "One man's wage rise is another man's price increase." - Harold Wilson

                          "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                          "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

                          _ Offline
                          _ Offline
                          _Flaviu
                          wrote on last edited by
                          #28

                          :D

                          1 Reply Last reply
                          0
                          • _ _Flaviu

                            #define DIR_NAME_LEN 2048

                            struct dir_struct
                            {
                            void* display;
                            char directory[DIR_NAME_LEN];
                            ...
                            ....

                            I have followed the way of how this variable is handled:

                            dir_struct_t dir_struct;

                            TRACE(\_T("Directory - %s\\n"), dir\_struct.directory); -> \_CrtDbgReport: String too long or IO Error
                            
                            strncpy(dir\_struct->directory, "/", sizeof(dir\_struct->directory));	
                            
                            TRACE(\_T("Directory - %s\\n"), dir\_struct->directory);	-> /
                            
                            strcat(dir\_struct->directory, current\_file->name);
                            
                            TRACE(\_T("Directory - %s\\n"), dir\_struct->directory);	-> \_CrtDbgReport: String too long or IO Error
                            

                            And if I look into VS debugger when I got "_CrtDbgReport: String too long or IO Error" from TRACE macro, I see the following result: see image.[^] and Untitled2 — Postimage.org[^] The line strcat(dir_struct->directory, current_file->name); is not quite correct ? I mean, correct for Windows, even if is correct for Linux ...

                            K Offline
                            K Offline
                            kalberts
                            wrote on last edited by
                            #29

                            I am really puzzled by how difficult it seem to be to explain how the value of that .directory was initialized. Where its value came from. How it was created. Obviously, whatever created the value did not follow the C convention of terminating it with a nul - most likely because it doesn't have a C origin. Fair enough. But why is it so difficult to show how the .directory value was obtained? As it now stands, it is like complaining "This variable should have av value between 0 and 100, but it is above 100. Why???" If you can't figure that out yourself, you must reveal how you calculate it, you cannot simply tell us how you use it, after it has gotten that out-of-range value- Your directory string is another out-of-range value. How you use it, after it got this illegal value is of no interest. The important thing is how it got that value, not how you later use it. Like if you ask "Why does my value exceed 100?" Noone can tell unless you tell how you got or calculated that value. String values are no different: If they have an illegal value, such as not being nul-terminated in contexts where that is expected, the problem is in the source, not in the use of the value. If it is as difficult as it seems to trace the source, identify where that directory sting came from, then you should not expect others to be able to help you. "I have an illegal value, but I can't tell where it came from - why is it not legal?" - noone can give you a reasonable answer to that. So come on, tell us how the .directory value was obtained/created! Until you do that, you cannot expect any useful help from other forum members

                            L _ 3 Replies Last reply
                            0
                            • K kalberts

                              I am really puzzled by how difficult it seem to be to explain how the value of that .directory was initialized. Where its value came from. How it was created. Obviously, whatever created the value did not follow the C convention of terminating it with a nul - most likely because it doesn't have a C origin. Fair enough. But why is it so difficult to show how the .directory value was obtained? As it now stands, it is like complaining "This variable should have av value between 0 and 100, but it is above 100. Why???" If you can't figure that out yourself, you must reveal how you calculate it, you cannot simply tell us how you use it, after it has gotten that out-of-range value- Your directory string is another out-of-range value. How you use it, after it got this illegal value is of no interest. The important thing is how it got that value, not how you later use it. Like if you ask "Why does my value exceed 100?" Noone can tell unless you tell how you got or calculated that value. String values are no different: If they have an illegal value, such as not being nul-terminated in contexts where that is expected, the problem is in the source, not in the use of the value. If it is as difficult as it seems to trace the source, identify where that directory sting came from, then you should not expect others to be able to help you. "I have an illegal value, but I can't tell where it came from - why is it not legal?" - noone can give you a reasonable answer to that. So come on, tell us how the .directory value was obtained/created! Until you do that, you cannot expect any useful help from other forum members

                              L Offline
                              L Offline
                              Lost User
                              wrote on last edited by
                              #30

                              I think you may be banging your head against a brick wall. I have tried this approach repeatedly and got nowhere. But well done for trying.

                              1 Reply Last reply
                              0
                              • K kalberts

                                I am really puzzled by how difficult it seem to be to explain how the value of that .directory was initialized. Where its value came from. How it was created. Obviously, whatever created the value did not follow the C convention of terminating it with a nul - most likely because it doesn't have a C origin. Fair enough. But why is it so difficult to show how the .directory value was obtained? As it now stands, it is like complaining "This variable should have av value between 0 and 100, but it is above 100. Why???" If you can't figure that out yourself, you must reveal how you calculate it, you cannot simply tell us how you use it, after it has gotten that out-of-range value- Your directory string is another out-of-range value. How you use it, after it got this illegal value is of no interest. The important thing is how it got that value, not how you later use it. Like if you ask "Why does my value exceed 100?" Noone can tell unless you tell how you got or calculated that value. String values are no different: If they have an illegal value, such as not being nul-terminated in contexts where that is expected, the problem is in the source, not in the use of the value. If it is as difficult as it seems to trace the source, identify where that directory sting came from, then you should not expect others to be able to help you. "I have an illegal value, but I can't tell where it came from - why is it not legal?" - noone can give you a reasonable answer to that. So come on, tell us how the .directory value was obtained/created! Until you do that, you cannot expect any useful help from other forum members

                                _ Offline
                                _ Offline
                                _Flaviu
                                wrote on last edited by
                                #31

                                I'll try myself the piece of code that I am putting here, by now I have taken the code from real project. I come back soon. I only need to move those structures in a test app and make it run.

                                1 Reply Last reply
                                0
                                • V Victor Nijegorodov

                                  The AnotherFunction itself or the way you are using it seems to be a reason of your problem... :|

                                  _ Offline
                                  _ Offline
                                  _Flaviu
                                  wrote on last edited by
                                  #32

                                  Yes Victor, you had right, from AnotherFunction is coming sometime a value like this: Oe©*BºcE«Mòצ£š{@Q—Y|†Š˜ b! And this AnotherFunction is list_entry_const() ... is coming from Linux, and to reproduced in a test project is quite difficult ... Now I have to see where is the starting point for that strange chars ...

                                  V 1 Reply Last reply
                                  0
                                  • _ _Flaviu

                                    Yes Victor, you had right, from AnotherFunction is coming sometime a value like this: Oe©*BºcE«Mòצ£š{@Q—Y|†Š˜ b! And this AnotherFunction is list_entry_const() ... is coming from Linux, and to reproduced in a test project is quite difficult ... Now I have to see where is the starting point for that strange chars ...

                                    V Offline
                                    V Offline
                                    Victor Nijegorodov
                                    wrote on last edited by
                                    #33

                                    It looks like this function returns some local variable that goes out of scope after returning. However, better would be looking in its sorce code.

                                    1 Reply Last reply
                                    0
                                    • K kalberts

                                      I am really puzzled by how difficult it seem to be to explain how the value of that .directory was initialized. Where its value came from. How it was created. Obviously, whatever created the value did not follow the C convention of terminating it with a nul - most likely because it doesn't have a C origin. Fair enough. But why is it so difficult to show how the .directory value was obtained? As it now stands, it is like complaining "This variable should have av value between 0 and 100, but it is above 100. Why???" If you can't figure that out yourself, you must reveal how you calculate it, you cannot simply tell us how you use it, after it has gotten that out-of-range value- Your directory string is another out-of-range value. How you use it, after it got this illegal value is of no interest. The important thing is how it got that value, not how you later use it. Like if you ask "Why does my value exceed 100?" Noone can tell unless you tell how you got or calculated that value. String values are no different: If they have an illegal value, such as not being nul-terminated in contexts where that is expected, the problem is in the source, not in the use of the value. If it is as difficult as it seems to trace the source, identify where that directory sting came from, then you should not expect others to be able to help you. "I have an illegal value, but I can't tell where it came from - why is it not legal?" - noone can give you a reasonable answer to that. So come on, tell us how the .directory value was obtained/created! Until you do that, you cannot expect any useful help from other forum members

                                      _ Offline
                                      _ Offline
                                      _Flaviu
                                      wrote on last edited by
                                      #34

                                      Here is what I've discovered by now:

                                      dir_data_t directory_data;
                                      strncpy(directory_data.current_directory, "/", sizeof(directory_data.current_directory));

                                      directory_data is ok by now.

                                      struct list_head* filewalker = NULL;
                                      file_info_t dirlist;
                                      logdir(&directory_data, &dirlist);
                                      INIT_LIST_HEAD(&dirlist.list);
                                      const file_info_t* current_file = NULL;
                                      list_for_each(filewalker, &dirlist.list)
                                      {
                                      current_file = list_entry_const(filewalker, const file_info_t, list);
                                      TRACE(_T("current_file->name %s\n"), current_file->name); // ->> now, sometime, current_file->name has a value like that: Oe©*BºcE«Mòצ£š{@Q—Y|†Š˜ b! and from now one, everything goes bad
                                      }

                                      after that,

                                      strcat(directory_data.current_directory, current_file->name);

                                      is not ok, of course. INIT_LIST_HEAD, list_for_each and list_entry_const are Linux functions. logdir functions I could not reproduced in a test app or write here because has many dependencies ... and to be everything more complicated, all this code is written in a recursive function .... is quite difficult to reproduced this situation in a test app ... I am trying to explore logdir function to see what I find there ...

                                      L 1 Reply Last reply
                                      0
                                      • _ _Flaviu

                                        Here is what I've discovered by now:

                                        dir_data_t directory_data;
                                        strncpy(directory_data.current_directory, "/", sizeof(directory_data.current_directory));

                                        directory_data is ok by now.

                                        struct list_head* filewalker = NULL;
                                        file_info_t dirlist;
                                        logdir(&directory_data, &dirlist);
                                        INIT_LIST_HEAD(&dirlist.list);
                                        const file_info_t* current_file = NULL;
                                        list_for_each(filewalker, &dirlist.list)
                                        {
                                        current_file = list_entry_const(filewalker, const file_info_t, list);
                                        TRACE(_T("current_file->name %s\n"), current_file->name); // ->> now, sometime, current_file->name has a value like that: Oe©*BºcE«Mòצ£š{@Q—Y|†Š˜ b! and from now one, everything goes bad
                                        }

                                        after that,

                                        strcat(directory_data.current_directory, current_file->name);

                                        is not ok, of course. INIT_LIST_HEAD, list_for_each and list_entry_const are Linux functions. logdir functions I could not reproduced in a test app or write here because has many dependencies ... and to be everything more complicated, all this code is written in a recursive function .... is quite difficult to reproduced this situation in a test app ... I am trying to explore logdir function to see what I find there ...

                                        L Offline
                                        L Offline
                                        Lost User
                                        wrote on last edited by
                                        #35

                                        That looks quite likely that some entries in your list are either corrupt, or have not been set to a valid entry.

                                        1 Reply Last reply
                                        0
                                        Reply
                                        • Reply as topic
                                        Log in to reply
                                        • Oldest to Newest
                                        • Newest to Oldest
                                        • Most Votes


                                        • Login

                                        • Don't have an account? Register

                                        • Login or register to search.
                                        • First post
                                          Last post
                                        0
                                        • Categories
                                        • Recent
                                        • Tags
                                        • Popular
                                        • World
                                        • Users
                                        • Groups