Loading ...
Sorry, an error occurred while loading the content.
 

Is there a hard coded char limit to argv buffers w/C++ on NSLU2?

Expand Messages
  • John
    Just started playing with my unslung NSLU2. I downloaded a project from source forge, and part of the build is a test tool, which is a fairly simple command
    Message 1 of 5 , Oct 28, 2005
      Just started playing with my unslung NSLU2.

      I downloaded a project from source forge, and part of the build is a
      test tool, which is a fairly simple command line tool.

      I noticed the tool was not getting the full parameter that I passed to
      it in the terminal, so I edited the .cpp code to add a line:

      std::cout << std::endl << "your argv[1] : " << argv[1] << std::end;

      Sure enough, the argv[1] appears to be truncated at 64 chars.

      Is this a limit of the C++ input? Can I increase the buffer size?
    • Phil Endecott
      ... I m not an Unslung expert, but my guess is that this is something that the shell is doing. (Does unslung use Bash or Ash or what?) What happens if you
      Message 2 of 5 , Oct 28, 2005
        > argv[1] appears to be truncated at 64 chars.

        I'm not an Unslung expert, but my guess is that this is something that
        the shell is doing. (Does unslung use Bash or Ash or what?)

        What happens if you just do

        $ echo abcdefghijk.... (i.e. >64 chars)

        ?

        --Phil.
      • John
        ... This works fine (in Bash), and in fact I had tried that. I did a tiny bit more testing, and also some additional info: 1) I m using Bash, installed via
        Message 3 of 5 , Oct 28, 2005
          > > argv[1] appears to be truncated at 64 chars.

          > I'm not an Unslung expert, but my guess is that this is something that
          > the shell is doing. (Does unslung use Bash or Ash or what?)

          > What happens if you just do

          > $ echo abcdefghijk.... (i.e. >64 chars)

          This works fine (in Bash), and in fact I had tried that. I did a tiny bit more testing, and also
          some additional info:

          1) I'm using Bash, installed via ipkg, not the default Ash shell.

          2) Ash does not have this problem.

          3) I discovered Bash is clipping chars based on the number of periods in the argument.

          for example:

          1.2.3 -> inputs as -> 1.
          1.2.3abc -> inputs as -> 1.2.3
          1.2.3abcd -> inputs as -> 1.2.3a

          from this pattern it seems that given n number of periods, n+1 chars will be truncated
          from the argument.
        • Phil Endecott
          ... Does echo 1.2.3 print 1. or 1.2.3 ? I d say it s more likely that something else in the program is corrupting argv before you look at it. Try a
          Message 4 of 5 , Oct 30, 2005
            > 3) I discovered Bash is clipping chars based on the number of periods in the argument.
            >
            > for example:
            >
            > 1.2.3 -> inputs as -> 1.
            > 1.2.3abc -> inputs as -> 1.2.3
            > 1.2.3abcd -> inputs as -> 1.2.3a
            >
            > from this pattern it seems that given n number of periods, n+1 chars will be truncated
            > from the argument.

            Does "echo 1.2.3" print "1." or "1.2.3" ?

            I'd say it's more likely that something else in the program is
            corrupting argv before you look at it. Try a simple thing like this:

            #include <stdio.h>

            int main(int argc, char* argv)
            {
            printf("argv[1]='%s'\n",argv[1]);
            }

            --Phil.
          • John
            ... echo works fine. ... I do believe you are correct. Although I put my cout statement just at the start of main, I put it after the variable declarations
            Message 5 of 5 , Oct 30, 2005
              --- In nslu2-general@yahoogroups.com, Phil Endecott <spam_from_nslu2_general@c...>
              wrote:

              > > 3) I discovered Bash is clipping chars based on the number of periods in the argument.

              > > 1.2.3abcd -> inputs as -> 1.2.3a

              > Does "echo 1.2.3" print "1." or "1.2.3" ?

              echo works fine.

              > I'd say it's more likely that something else in the program is
              > corrupting argv before you look at it. Try a simple thing like this...

              I do believe you are correct. Although I put my cout statement just at the start of main, I put
              it after the variable declarations and there is one C++ class variable that gets instantiated
              before my call to cout. Apparently something in the constructor is messing with argv.
              Moving the cout call to before the object declaration makes the problem go away.

              Thanks for the feedback.
            Your message has been successfully submitted and would be delivered to recipients shortly.