0

When compiling the application in Visual Studio 2017 - the output log displays errors with the content as below:

warning: flag '0' results in undefined behavior with 's' conversion specifier [-Wformat]
                printf("[ERROR] START/END IsGreater %064s \n", maxKey.GetBase16().c_str());
                                                    ~^~~~
warning: flag '0' results in undefined behavior with 's' conversion specifier [-Wformat]
               printf("[load] start=%064s \n", bc->ksStart.GetBase16().c_str());
                                    ~^~~~
warning: flag '0' results in undefined behavior with 's' conversion specifier [-Wformat]
               printf("[load]  next=%064s \n", bc->ksNext.GetBase16().c_str());
                                    ~^~~~
warning: flag '0' results in undefined behavior with 's' conversion specifier [-Wformat]
               printf("[load]   end=%064s \n", bc->ksFinish.GetBase16().c_str());
                                    ~^~~~
warning: flag '0' results in undefined behavior with 's' conversion specifier [-Wformat]
              fprintf(f, "Priv (HEX): 0x%064s\n", pAddrHex.c_str());
                                        ~^~~~
warning: ISO C++11 does not allow conversion from string literal to 'char *' [-Wwritable-strings]
            lambda.SetBase16("5363ad4cc05c30e0a5261c028812645a122e22ea20816678df02967c1b23bd72");

How should it look correct to eliminate existing problems?

Here are the parts cut from the source code of the file in question:

void checkKeySpace(BITCRACK_PARAM * bc, Int& maxKey) {

    if (bc->ksStart.IsGreater(&maxKey) || bc->ksFinish.IsGreater(&maxKey)) {
        printf("[ERROR] START/END IsGreater %064s \n", maxKey.GetBase16().c_str());
        exit(-1);
    }
    if (bc->ksFinish.IsLowerOrEqual(&bc->ksStart)) {
        printf("[ERROR] END IsLowerOrEqual START \n");
        exit(-1);
    }
    if (bc->ksFinish.IsLowerOrEqual(&bc->ksNext)) {
        printf("[ERROR] END: IsLowerOrEqual NEXT \n");
        exit(-1);
    }

    return;
}
void reconstructAdd(Secp256K1 *secp, string fileName, string outputFile, string privAddr) {

  bool compressed;
  int addrType;
  Int lambda;
  Int lambda2;
  lambda.SetBase16("5363ad4cc05c30e0a5261c028812645a122e22ea20816678df02967c1b23bd72");
  lambda2.SetBase16("ac9c52b33fa3cf1f5ad9e3fd77ed9ba4a880b9fc8ec739c2e0cfc810b51283ce");

  Int privKey = secp->DecodePrivateKey((char *)privAddr.c_str(),&compressed);
  if(privKey.IsNegative())
    exit(-1);
ADMlN
  • 1
  • Why do you even need that 0? %s indeed doesn't have anything like that but I believe your strings will be of the correct length anyway and not need any padding. – Paul Stelian Nov 12 '19 at 20:53
  • The application searches for empty wallet addresses using the prefix of its choice. As the whole works on SECP256K1, and the search can be done from the point of your choice (e.g. 1) in HEX, and the progress is saved to a text file - zeros must precede the correct string because they are part of the key – ADMlN Nov 12 '19 at 21:18
  • 1
    @ADMlN you probably want to open a new question with your code that implements the zero padding if you want help with this function / have a bug or can't get it to work. You will likely have to add a [mcve] for that in the new question. – drescherjm Nov 12 '19 at 21:35

1 Answers1

4

For the %s format specifier, zero padding isn't defined in the standard; it's only valid for these conversions: %d, %i, %o, %u, %x, %X, %a, %A, %e, %E, %f, %F, %g, and %G.

Here's a quote from cppreference:

0 : for integer and floating point number conversions, leading zeros are used to pad the field instead of space characters. For integer numbers it is ignored if the precision is explicitly specified. For other conversions using this flag results in undefined behavior. It is ignored if - flag is present.

That's what your compiler warns about.

P.P
  • 117,907
  • 20
  • 175
  • 238
  • 1
    ***how to fix code?*** Write a function to zero pad your string maybe use this: [https://stackoverflow.com/questions/6143824/add-leading-zeros-to-string-without-sprintf](https://stackoverflow.com/questions/6143824/add-leading-zeros-to-string-without-sprintf) it would be simpler if you were not using printf() – drescherjm Nov 12 '19 at 20:20
  • Just drop the leading 0 from the format specifier? If you do want to zero pad then you can roll out your own function that does that. – P.P Nov 12 '19 at 20:22
  • Zeros are part of the string that is the solution key. They are supposed to appear, write or whatever in the case when they appear there ... and these ARE occurring in the case of SECP256K1 – ADMlN Nov 12 '19 at 21:21