From c8d1e79e1da0f262cdae1e2ed3626f3e1607954d Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Mon, 24 Jun 2024 09:43:27 +0200 Subject: [PATCH] Corregido bug en el FADE_RANDOM_SQUARE al acceder a elementos fuera del vector --- Makefile | 14 ++++++++------ source/fade.cpp | 3 ++- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 74cff43..9b79184 100644 --- a/Makefile +++ b/Makefile @@ -23,16 +23,18 @@ INCLUDES:= -I$(DIR_SOURCES) # Variables segĂșn el sistema operativo ifeq ($(OS),Windows_NT) + FixPath = $(subst /,\,$1) SOURCES := source/*.cpp source/common/*.cpp CXXFLAGS:= -std=c++11 -Wall -Os -ffunction-sections -fdata-sections -Wl,--gc-sections -static-libstdc++ -Wl,-subsystem,windows LDFLAGS := -lmingw32 -lws2_32 -lSDL2main -lSDL2 - RM:= rmdir /Q /S - MKD:= + RM = del /Q + MKD:= mkdir else + FixPath = $1 SOURCES := $(shell find $(DIR_SOURCES) -name '*.cpp') CXXFLAGS:= -std=c++11 -Wall -Os -ffunction-sections -fdata-sections LDFLAGS := -lSDL2 - RM:= rm -rdf + RM = rm -f MKD:= mkdir -p endif @@ -54,11 +56,11 @@ all: a1 a1: $(TARGET_FILE) $(TARGET_FILE): $(OBJECTS) - mkdir -p $(@D) + $(MKD) $(@D) $(CXX) $(OBJECTS) $(LDFLAGS) -o $(TARGET_FILE) $(DIR_BUILD)%.o: $(DIR_SOURCES)%.cpp - mkdir -p $(@D) + $(MKD) $(@D) $(CXX) -c $< $(CXXFLAGS) $(INCLUDES) -o $@ -include $(DEPENDENCIES) @@ -72,7 +74,7 @@ $(DIR_BUILD)%.o: $(DIR_SOURCES)%.cpp .PHONY: clean clean: - $(RM) $(DIR_BUILD) + $(RM) $(call FixPath,$(DIR_BUILD)) ############################################################################### # # diff --git a/source/fade.cpp b/source/fade.cpp index 78c3cc4..82bd256 100644 --- a/source/fade.cpp +++ b/source/fade.cpp @@ -133,7 +133,8 @@ void Fade::update() const int index = std::min(counter / fadeRandomSquaresDelay, (numSquaresWidth * numSquaresHeight) - 1); for (int i = 0; i < fadeRandomSquaresMult; ++i) { - SDL_RenderFillRect(renderer, &square[index * fadeRandomSquaresMult + i]); + const int index2 = std::min(index * fadeRandomSquaresMult + i, (int)square.size() - 1); + SDL_RenderFillRect(renderer, &square[index2]); } // Volvemos a usar el renderizador de forma normal