xunzhang / gflags

Automatically exported from code.google.com/p/gflags
BSD 3-Clause "New" or "Revised" License
1 stars 0 forks source link

Bug with using --help for description longer than 128 bytes. #48

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Compile version 1.6 using Visual Studio 2008
2. Create a simple main.cpp program as follows:

#include <gflags/gflags.h>
int main(int argc, char* argv[])
{
    google::ParseCommandLineFlags(&argc, &argv, true);
    return 0;
}

3. Run it with "--help" as the argument.

What is the expected output? What do you see instead?
It will blow up on the first assert in 
gflags_reporting.cc:DescribeOneFlag(const CommandLineFlagInfo& flag).

This is because the flag.description is truncated in SStringPrintf, since the 
util.h:InternalStringPrintf() contains a bug.

Basically the space[128] buffer is reused wrongly in the second loop, which 
tries to reformat the string with a bigger buffer. Instead of using 
  vsnprintf(buf, length, ...)
it is
  vsnprintf(space, length, ...)

Which uses the wrong buffer.

What version of the product are you using? On what operating system?
This bug should be present on most platforms as far as I can tell from the 
code. Basically, it will currently blow up when running "--help" where the 
description is longer than 128 bytes.

Please provide any additional information below.

A patch is attached.

Original issue reported on code.google.com by cyberm...@gmail.com on 16 Aug 2011 at 12:12

Attachments:

GoogleCodeExporter commented 9 years ago

Original comment by `` on 18 Jan 2012 at 2:23

GoogleCodeExporter commented 9 years ago

Original comment by csilv...@gmail.com on 16 Aug 2011 at 7:03