Блог пользователя farmersrice

Автор farmersrice, история, 7 лет назад, По-английски

http://mirror.codeforces.com/contest/963/submission/37451734

Not sure where my code has a bug, but I submitted 3 times and it's always the same error on test 48.

I could not decipher this part of the message:

Diagnostics detected issues [cpp.clang++-diagnose]: =================================================================
==6068==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x14e00978 at pc 0x00dc63fd bp 0x1355f754 sp 0x1355f750
READ of size 4 at 0x14e00978 thread T0

I would appreciate any help. Thanks!

  • Проголосовать: нравится
  • +5
  • Проголосовать: не нравится

»
7 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Hmm, I fixed some possible string out of bounds issues but it's still failing

http://mirror.codeforces.com/contest/963/submission/37452849

»
7 лет назад, # |
  Проголосовать: нравится +16 Проголосовать: не нравится

Is your address 6969 or something that you need Address Sanitizer

»
7 лет назад, # |
  Проголосовать: нравится +10 Проголосовать: не нравится

Subtracting k from possible.size() can do bad things, since possible.size() is an unsigned int.

»
6 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится
  • »
    »
    6 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    Local arrays with variable length are illegal in C++.

    int n = 5;
    char c[n]; // Compilation error
    
    const int n = 5;
    char c[n]; // OK
    

    But in G++11 it's sometimes correct on small lengths. Two key words there are sometimes and small. I can't surely say is it UB or not, but it's surely wrong C++ code.

    Three options: 1) Use global array with big enought const length;
    2) Use stl-vector;
    3) Use new-statement to construct array.

    • »
      »
      »
      6 лет назад, # ^ |
        Проголосовать: нравится +26 Проголосовать: не нравится

      Variable length arrays are an extension supported by GCC.

      I'd like to point out a possible misunderstanding of what a language extension is. Compiler authors don't just go like "here's an extension, and it sometimes works, but sometimes doesn't so take care". If it's supported by the compiler, it should work as documented for the intended uses, same as all other language features do.

      Also, the name of the extension may be confusing. Actually, the memory is allocated at the point of declaration. If we change the vaule of n afterwards, the array itself does not change in any way.

      • »
        »
        »
        »
        6 лет назад, # ^ |
          Проголосовать: нравится +15 Проголосовать: не нравится

        Thanks for GCC extensions, now I know something new. Though I still stick with standartized C++.

        But what ASan complains about if it is not non-const length array?

      • »
        »
        »
        »
        6 лет назад, # ^ |
          Проголосовать: нравится +10 Проголосовать: не нравится

        However it's JUST an extension and has many bugs. See PR16694. I just hate VLA personally.

        • »
          »
          »
          »
          »
          6 лет назад, # ^ |
            Проголосовать: нравится 0 Проголосовать: не нравится

          There's only 11 issues related to variable-length arrays, and not all of them are bugs? I'd say they are in an OK shape then.

          To me, it looks like most of the actual bugs are triggered by bad user code. Well, that's what bad code does: it does not work, one way or another. This time it's a compiler's fault, but whatever.

          Of course, if you don't like a feature, you don't have to use it. C++ is rich with features, plenty to choose form.

          • »
            »
            »
            »
            »
            »
            6 лет назад, # ^ |
              Проголосовать: нравится +23 Проголосовать: не нравится

            In my opinion the usage of VLA in C++ is exactly an instance of bad user code :). It's not standardized so other compilers may reject it and give me an CE.

            It depends on how to define "bad user code". I (and GCC) believe int a[2][n] is bad user code (unless n is a macro expanding to some constexpr). See PR58646. But in a new programmer's view it may be "perfectly well".

            Once a student really blamed me (problem setter) because his usage of VLA in C++ triggered a compiler bug. I tried to reason with him but he just insisted that his program was "perfectly well". I was irritated.

»
6 лет назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

http://mirror.codeforces.com/contest/1041/submission/45163366

Can Somebody Help me with this code.

I dont Know Whats Wrong..

»
5 лет назад, # |
  Проголосовать: нравится -14 Проголосовать: не нравится
»
4 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

https://mirror.codeforces.com/contest/1242/submission/85228209 Can anyone help with this? I am getting runtime error

  • »
    »
    4 года назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    It seems after S.erase() in some deep recursive call you have invalid iterator in outer dfs(). I changed set<int> S; for map<int, bool> S; + corresponding management, and it worked.