diff --git a/src/detection/cpu/cpu_linux.c b/src/detection/cpu/cpu_linux.c index fcce77f66..badc3ae57 100644 --- a/src/detection/cpu/cpu_linux.c +++ b/src/detection/cpu/cpu_linux.c @@ -196,6 +196,7 @@ static void detectArmName(FFstrbuf* cpuinfo, FFCPUResult* cpu, uint32_t implId) { // https://github.com/Dr-Noob/cpufetch/issues/213#issuecomment-1927782105 ffStrbufSetStatic(&cpu->name, "Virtualized Apple Silicon"); + ffStrbufGetlineRestore(&line, &len, cpuinfo); return; } name = applePartId2name(partId); @@ -251,7 +252,10 @@ static const char* parseCpuInfo( && cpu->name.length > 0 // #1202 #1204 #endif ) + { + ffStrbufGetlineRestore(&line, &len, cpuinfo); break; + } (void)( // arm64 doesn't have "model name"; arm32 does have "model name" but its value is not useful. @@ -520,6 +524,8 @@ const char* ffDetectCPUImpl(const FFCPUOptions* options, FFCPUResult* cpu) cpu->coresPhysical = (uint16_t) ffStrbufToUInt(&physicalCoresBuffer, cpu->coresLogical); #if __x86_64__ || __i386__ cpu->packages = getPackageCount(&cpuinfo); + if (cpu->packages > 1) + cpu->coresPhysical *= cpu->packages; #endif // Ref https://github.com/fastfetch-cli/fastfetch/issues/1194#issuecomment-2295058252 diff --git a/src/util/FFstrbuf.c b/src/util/FFstrbuf.c index 44d7f43d1..32692907a 100644 --- a/src/util/FFstrbuf.c +++ b/src/util/FFstrbuf.c @@ -570,6 +570,22 @@ bool ffStrbufGetline(char** lineptr, size_t* n, FFstrbuf* buffer) return true; } +/// @brief Restore the end of a line that was modified by ffStrbufGetline. +/// @warning This function should be called before breaking an ffStrbufGetline loop. +void ffStrbufGetlineRestore(char** lineptr, size_t* n, FFstrbuf* buffer) +{ + assert(buffer && lineptr && n); + assert(buffer->allocated > 0 || (buffer->allocated == 0 && buffer->length == 0)); + assert(!*lineptr || (*lineptr >= buffer->chars && *lineptr <= buffer->chars + buffer->length)); + + if (!*lineptr) + return; + + *lineptr += *n; + if (*lineptr < buffer->chars + buffer->length) + **lineptr = '\n'; +} + bool ffStrbufRemoveDupWhitespaces(FFstrbuf* strbuf) { if (strbuf->allocated == 0) return false; // Doesn't work with static strings diff --git a/src/util/FFstrbuf.h b/src/util/FFstrbuf.h index aff9395f7..a3bce4ca6 100644 --- a/src/util/FFstrbuf.h +++ b/src/util/FFstrbuf.h @@ -90,6 +90,7 @@ void ffStrbufUpperCase(FFstrbuf* strbuf); void ffStrbufLowerCase(FFstrbuf* strbuf); bool ffStrbufGetline(char** lineptr, size_t* n, FFstrbuf* buffer); +void ffStrbufGetlineRestore(char** lineptr, size_t* n, FFstrbuf* buffer); bool ffStrbufRemoveDupWhitespaces(FFstrbuf* strbuf); FF_C_NODISCARD static inline FFstrbuf ffStrbufCreateA(uint32_t allocate)