#51 PosixTimeval bugs

v1.0_(example)
open
nobody
None
4
2014-07-23
2014-07-23
zhiying678
No

Hi,there!
I find a simple bug in the implement of PosixTimeval class ToString() method when using it to distill the timestamp information.

source code file: PosixTimeval.cs
line 271 sb.Append(MicroSeconds);

when MicroSeconds is a small value with several leading zeros,the zeros will be omitted.
my test code below:

            PosixTimeval pt1 = new PosixTimeval(1, 000009);
            string timestr = pt1.ToString();
            PosixTimeval pt3 = new PosixTimeval(1, 900000);
            string timestr3 = pt3.ToString();

where the two strings timestr and timestr3 will be set the same value.

I try to fix this bug like this:

        public override System.String ToString()
        {
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            sb.Append(Seconds);
            sb.Append('.');
            sb.Append(MicroSeconds.ToString("000000"));
            sb.Append('s');

            return sb.ToString();
        }

and also I feel the constructor of PosixTimeval should add a judgement:

        public PosixTimeval(ulong Seconds, ulong MicroSeconds)
        {
            if (MicroSeconds >= 1000000)
                throw new PcapException("MicroSeconds too big!");
            this.Seconds = Seconds;
            this.MicroSeconds = MicroSeconds;
        }

btw,SharpPcap is a great work,appreciate a lot,forgive my pool expression.

Discussion

  • Chris Morgan
    Chris Morgan
    2014-07-23

    Ahh I see. If you'd like to see the bug corrected I would need a git patch (or a pull request) that fixes the first issue and adds a unit test to the existing unit test system that would fail without your fix.

    The second also appears like it could be an issue but the same applies, I'd need a git patch or pull request that fixes only this second issue.

    Alternatively I may get to doing this in the next several months but life always seems to get in the way.

     
    • zhiying678
      zhiying678
      2014-07-24

      I have commit one pull request,but not familiar with unit test system that you said.

       
  • Chris Morgan
    Chris Morgan
    2014-07-23

    Btw, you can reach me probably more easily at my personal email, chmorgan@gmail.com. These forums don't allow for bidirectional email participation, require logging in etc.

     


Anonymous


Cancel   Add attachments