A C++ task from Yandex

At an interview I was asked how to by a given vector of integers build resulting vector containing the products of all the elements except current. Below I provided my solution in C++:

#include <vector>
#include <iostream>

using V = std::vector<int>;

V func(const V& v)
{
    V result;
    result.resize(v.size());

    int product = 1;

    for (size_t pos = 0; pos != v.size(); ++pos)
    {
        result[pos] = product;

        int a = v[pos];
        product *= a;
    }
(more…)

Bought a terribly annoying video recorder from ZOSI

Its Windows client simply crashes with the following message:

My device model number is ZR08WN HDD:2TB and the device QR code ends with 111A:

(more…)

I transferred my domains to another registration service provider

My Russian registration service provider has stopped working, but PublicDomainRegistry.com sent me the codes and I was able to transfer my domains to some ResellerClub prvider:

(more…)

Range-based for loop with universal reference.

It is possible to iterate over std::vector with &&:

#include <vector>

class A {};

int main()
{
    std::vector<A> vec;
    for (auto&& v : vec)
    {
        static_cast<void>(v);
    }

    return 0;
}

Links:

An annoying question about auto in C++

I was recently asked during a C++ job interview what are the types of riN variables in the code below:

int val = 25;

int foo() { return val; }
int& foo1() { return val; }
//warning: type qualifiers ignored on function return type
/*const*/ int foo2() { return val; }
const int& foo3() { return val; }

int main()
{
  auto ri = foo(); 
  auto ri1 = foo1();
  auto ri2 = foo2();
  auto ri3 = foo3();

  //cannot bind non-const lvalue reference of type 'int&' to an rvalue of type 'int'
  //auto& ri4 = foo();
  auto& ri5 = foo1();
  //cannot bind non-const lvalue reference of type 'int&' to an rvalue of type 'int'
  //auto& ri6 = foo2();
  auto& ri7 = foo3();

  auto&& ri8 = foo();
  auto&& ri9 = foo1();
  auto&& ri10 = foo2();
  auto&& ri11 = foo3();
    
  return 0;
}

auto ignores the type qualifiers and references, so looks like the types are simply int, int& and int&&.

My QT Android app periodically crashes at android::RefBase::incStrong(void const*)

The call stack is:

  #00  pc 00000000000097a8  /system/lib/libutils.so (android::RefBase::incStrong(void const*) const+4)
  #00  pc 0000000000022145  /vendor/lib/libIMGegl.so
  #00  pc 000000000000ab79  /vendor/lib/libIMGegl.so (KEGLGetDrawableParameters+252)
  #00  pc 0000000000041c53  /vendor/lib/egl/libGLESv2_mtk.so
  #00  pc 000000000001663d  /vendor/lib/egl/libGLESv2_mtk.so
  #00  pc 0000000000016b01  /vendor/lib/egl/libGLESv2_mtk.so (glClear+440)
  #00  pc 000000000008acaf  /data/app/net.geographx.LinesGame-9_pUex92-tGEqE4iIbRCCw==/lib/arm/libLinesGameQt_armeabi-v7a.so (LinesGame::Squircle::beforeRendering()+270)
  #00  pc 000000000017d5b9  /data/app/net.geographx.LinesGame-9_pUex92-tGEqE4iIbRCCw==/lib/arm/libQt5Core_armeabi-v7a.so
  #00  pc 0000000000176f4d  /data/app/net.geographx.LinesGame-9_pUex92-tGEqE4iIbRCCw==/lib/arm/libQt5Quick_armeabi-v7a.so (QQuickWindowPrivate::renderSceneGraph(QSize const&, QSize const&)+172)

It is a QT bug that is not fixed yet.

Also my app crashes at the destructor of std::thread and this also a QT bug that is not fixed yet.

The performance of my SSD NVMe drives

Below I proved the results of speed tests of my 500 GB SSD M.2 Kingston NV1 [SNVS/500G] and 500 GB SSD M.2 Seagate BarraCuda Q5 [ZP500CV3A001]:

------------------------------------------------------------------------------
CrystalDiskMark 8.0.1 x64 (UWP) (C) 2007-2021 hiyohiyo
                                  Crystal Dew World: https://crystalmark.info/
------------------------------------------------------------------------------
* MB/s = 1,000,000 bytes/s [SATA/600 = 600,000,000 bytes/s]
* KB = 1000 bytes, KiB = 1024 bytes

[Read]
  SEQ    1MiB (Q=  8, T= 1):  2546.163 MB/s [   2428.2 IOPS] <  3291.40 us>
  SEQ    1MiB (Q=  1, T= 1):     0.000 MB/s [      0.0 IOPS] <     0.00 us>
  RND    4KiB (Q= 32, T= 1):   449.897 MB/s [ 109838.1 IOPS] <   281.99 us>
  RND    4KiB (Q=  1, T= 1):     0.000 MB/s [      0.0 IOPS] <     0.00 us>

[Write]
  SEQ    1MiB (Q=  8, T= 1):  1970.445 MB/s [   1879.2 IOPS] <  4243.49 us>
  SEQ    1MiB (Q=  1, T= 1):     0.000 MB/s [      0.0 IOPS] <     0.00 us>
  RND    4KiB (Q= 32, T= 1):   310.284 MB/s [  75752.9 IOPS] <   417.44 us>
  RND    4KiB (Q=  1, T= 1):     0.000 MB/s [      0.0 IOPS] <     0.00 us>

Profile: Default
   Test: 1 GiB (x5) [D: 18% (85/466GiB)]
   Mode:
   Time: Measure 5 sec / Interval 5 sec 
   Date: 2021/05/16 13:23:57
     OS: Windows 10 Professional [10.0 Build 19041] (x64)
(more…)

Applying a path that fixes a bug in QT 5.15.2

There was a bug in QT 5.15.2 that results in app crash on Android 5.1 and a patch:

Submodule qtbase contains modified content
diff --git a/qtbase/src/corelib/plugin/qlibrary_unix.cpp b/qtbase/src/corelib/plugin/qlibrary_unix.cpp
index a5c72f81d9..5cd21b67a4 100644
--- a/qtbase/src/corelib/plugin/qlibrary_unix.cpp
+++ b/qtbase/src/corelib/plugin/qlibrary_unix.cpp
@@ -243,10 +243,10 @@ bool QLibraryPrivate::load_sys()
             }
             if (hnd) {
                 using JniOnLoadPtr = jint (*)(JavaVM *vm, void *reserved);
-                JniOnLoadPtr jniOnLoad = reinterpret_cast<JniOnLoadPtr>(dlsym(pHnd, "JNI_OnLoad"));
+                JniOnLoadPtr jniOnLoad = reinterpret_cast<JniOnLoadPtr>(dlsym(hnd, "JNI_OnLoad"));
                 if (jniOnLoad && jniOnLoad(QtAndroidPrivate::javaVM(), nullptr) == JNI_ERR) {
                     dlclose(hnd);
-                    pHnd = nullptr;
+                    hnd = nullptr;
                 }
             }
 #endif

Looks like it was simply a typo and pHnd was replaced with hnd.

QT 5.15.3 where the bug was fixed is commercial so I applied the patch by myself (thanks to danilabagroff from stackoverflow.com):

(more…)

Building QT 6.1.0 for Android on Windows

Theoretically it can be:

git clone --recursive https://code.qt.io/qt/qt5.git --branch v6.1.0

or alternatively:

git clone https://code.qt.io/qt/qt5.git --branch v6.1.0
./init-repository --branch --module-subset=essential,qtandroidextras,qtsvg,qtquickcontrols2,qtgraphicaleffects,qtwebsockets,qtmultimedia

or

./init-repository --module-subset=all
(more…)

QT 5.15.2 app crashes on Android 5.1

My QT 5.15.2 app crashes on Android 5.1 with the following call stack:

*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
Build fingerprint: 'Android/sdk_google_phone_x86_64/generic_x86_64:5.1.1/LMY48X/6402608:userdebug/test-keys'
Revision: '0'
ABI: 'x86_64'
pid: 3954, tid: 3998, name: qtMainLoopThrea  >>> net.geographx.LinesGame <<<
signal 6 (SIGABRT), code -6 (SI_TKILL), fault addr --------
Abort message: 'art/runtime/mirror/art_method.cc:356] Check failed: !IsFastNative() int java.lang.Character.digitImpl!(int, int)'
    rax 0000000000000000  rbx 0000000000000f9e  rcx ffffffffffffffff  rdx 0000000000000006
    rsi 0000000000000f9e  rdi 0000000000000f72
    r8  0000000000000022  r9  0000000000000002  r10 0000000000000008  r11 0000000000000206
    r12 000000000000000b  r13 0000000000000006  r14 00007f747b51a000  r15 0000000000000051
    cs  0000000000000033  ss  000000000000002b
    rip 00007f7488099e37  rbp 00007f7467007b70  rsp 00007f74670063e8  eflags 0000000000000206
(more…)