Probably a bug in juce_getCpuVendor()


The stack is corrupted in _getCpuVendor() function

to reproduce the bug, I used the example project included in juce 1.26, line 48:

  •    g.drawText (T("click on this window to quit..."),
  •    g.drawText (SystemStats::getCpuVendor(),

The error gets spotted by visual c++ 2003, when in debug build.
“RTC failure #2 - Stack around the variable ‘vendor’ was corrupted”.

In release build, the resulting string is empty.

My cpu is reported by windows as “AMD Athlon™ 64 Processor”.



I just had a fix in for this one:

static void juce_getCpuVendor (char* const v)
    int vendor[4];
    zeromem (vendor, 16);



        __asm__ __volatile__ (
            "movl 0, %%eax             \n\
             cpuid                     \n\
             movl %%ebx, %[vendor1]    \n\
             movl %%edx, %[vendor2]    \n\
             movl %%ecx, %[vendor3]"
             : [vendor1] "m" (vendor[0]),
               [vendor2] "m" (vendor[1]),
               [vendor3] "m" (vendor[2])
             : "cc", "eax", "ebx", "ecx", "edx", "memory");

            mov eax, 0
            mov [vendor], ebx
            mov [vendor + 4], edx
            mov [vendor + 8], ecx


        *v = 0;

    memcpy (v, vendor, 16);