fixed problem with int / long conversion and unsigned oopies. overflows of ints should not occur as often
sophuwu sophie@sophuwu.site
Tue, 07 Nov 2023 21:35:30 +0100
3 files changed,
16 insertions(+),
16 deletions(-)
M
CMakeLists.txt
→
CMakeLists.txt
@@ -1,6 +1,6 @@
-cmake_minimum_required(VERSION 3.0) +cmake_minimum_required(VERSION 3.16) project(rls) set(CMAKE_CXX_STANDARD 17) -add_executable(${CMAKE_PROJECT_NAME} main.cpp) +add_executable(rls main.cpp)
M
Makefile
→
Makefile
@@ -1,6 +1,6 @@
ifeq ($(shell command -v cmake), ) -COMPCMD = $(CC) --std=c++17 -o build/rls main.cpp -COMPMSG = $(CC) +COMPCMD = g++ --std=c++17 -o build/rls main.cpp +COMPMSG = g++ else ifeq ($(shell command -v ninja), ) COMPCMD = cmake -S . -B build && cmake --build build@@ -20,7 +20,7 @@ endif
ifeq ($(shell command -v upx), ) UPXCMD = echo UPX not found. Binary size may be larger than expected. else -UPXCMD = upx --best build/rls +UPXCMD = upx --best build/rls > /dev/null endif build: main.cpp $(CMAKELISTS)@@ -30,11 +30,11 @@ @mkdir -p build
@$(COMPCMD) @echo Compiled successfully. @echo Program is located at build/rls. - @echo \"make small\" to reduce binary size. Requires strip and/or upx. - @echo \"sudo make install\" to install the program into /usr/local/bin. - @echo And \"make clean\" to remove the build directory. + @echo "make small" to reduce binary size. Requires strip and/or upx. + @echo "sudo make install" to install the program into /usr/local/bin. + @echo And "make clean" to remove the build directory. -clean: build +clean: build/ @echo Cleaning up. @rm -rf build @echo Cleaned up successfully.@@ -44,7 +44,7 @@ @cp build/rls build/rls.bak
@echo Stripping binary. @$(STRIPCMD) @$(UPXCMD) - @echo Old Sise: && du -sh build/rls.bak + @echo Old Size: && du -sh build/rls.bak @echo New size: && du -sh build/rls@@ -52,4 +52,4 @@ install: build/rls
@echo Installing to /usr/local/bin. @sudo cp build/rls /usr/local/bin/rls @echo Installed successfully. - @echo Run \"rls\" to use the program. + @echo Run "rls" to use the program.
M
main.cpp
→
main.cpp
@@ -53,7 +53,7 @@ struct rainbow {
rgb c; double s = 0; // step - void init(int len) { + void init(unsigned int len) { if (len == 0) panic("Divison by zero."); c.set(255, 0, 0); s = 5.0*255.0 / (double)len;@@ -95,10 +95,10 @@ std::string size;
std::string str() {return size + name + "\n";} }; -std::string convsize(int n) { - float f = n; +std::string convsize(unsigned long n) { + double f = n; char c[] = " KMGT"; - int i = 0; + unsigned long i = 0; for (;f > 999; i++) f /= 1000; if (i > 4) return " >1.00 P "; n = 100*f;@@ -200,6 +200,6 @@ r.print2d(" "+dirlist[i], len);
r.next(); } r.print2d("Folders / Files / Total: " + std::to_string(folders.size()) + '/' + std::to_string(files.size()) + '/' + std::to_string(folders.size()+files.size()) + '\n', len); - + printf("\033[0m"); return 0; }