1. Список говнокодов пользователя HO9I6PbCKuu_neTyx

    Всего: 1

  2. C++ / Говнокод #27785

    +3

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    template<typename T>
    static ALWAYS_INLINE void FormatLogMessageAndPrintW(
                                                 const char* channelName, 
                                                 const char* functionName, 
                                                 LOGLEVEL level,
                                                 const char* message, 
                                                 bool timestamp, 
                                                 bool ansi_color_code,
                                                 bool newline, 
                                                 const T& callback)
    {
      char buf[512];
      char* message_buf = buf;
      int message_len;
      if ((message_len = FormatLogMessageForDisplay(message_buf,
                           sizeof(buf), channelName, functionName,
                           level, 
                           message, timestamp,
                           ansi_color_code, newline)) > (sizeof(buf) - 1))
      {
        message_buf = static_cast<char*>(std::malloc(message_len + 1));
        message_len = FormatLogMessageForDisplay(message_buf, 
                     message_len + 1, channelName, functionName, 
                     level, message, timestamp, ansi_color_code, newline);
      }
      if (message_len <= 0)
        return;
    
      // Convert to UTF-16 first so unicode characters display correctly.
      // NT is going to do it anyway...
      wchar_t wbuf[512];
      wchar_t* wmessage_buf = wbuf;
      int wmessage_buflen = countof(wbuf) - 1;
      if (message_len >= countof(wbuf))
      {
        wmessage_buflen = message_len;
        wmessage_buf = static_cast<wchar_t*>
                   (std::malloc((wmessage_buflen + 1) * sizeof(wchar_t)));
      }
    
      wmessage_buflen = MultiByteToWideChar(CP_UTF8, 0, message_buf,
                        message_len, wmessage_buf, wmessage_buflen);
    
      if (wmessage_buflen <= 0)
        return;
    
      wmessage_buf[wmessage_buflen] = '\0';
      callback(wmessage_buf, wmessage_buflen);
    
      if (wmessage_buf != wbuf)
      {
        std::free(wbuf);                        // <=
      }
    
      if (message_buf != buf)
      {
        std::free(message_buf);
      }
    }

    Отсюда:
    https://pvs-studio.com/ru/blog/posts/cpp/0880/

    HO9I6PbCKuu_neTyx, 03 Ноября 2021

    Комментарии (31)