Skip to content

Commit 25d2bc9

Browse files
authored
Merge pull request #2 from codetheuri/alert-autofix-2
Potential fix for code scanning alert no. 2: Incorrect conversion between integer types
2 parents a71a5d1 + 4b47dd8 commit 25d2bc9

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

internal/app/handlers/todo.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"encoding/json"
55
"net/http"
66
"strconv"
7+
"math"
78

89
"github.com/codetheuri/todolist/internal/app/services"
910
appErrors "github.com/codetheuri/todolist/pkg/errors"
@@ -63,6 +64,12 @@ func (h *TodoHandler) GetTodoByID(w http.ResponseWriter, r *http.Request) {
6364
web.RespondError(w, appErrors.ValidationError("Invalid ID format", err, nil), http.StatusBadRequest)
6465
return
6566
}
67+
// Check if the parsed ID is within the bounds of the uint type
68+
if id > math.MaxUint {
69+
h.log.Warn("Handler: ID exceeds the maximum allowed value for uint", "id", id)
70+
web.RespondError(w, appErrors.ValidationError("ID exceeds the maximum allowed value", nil, nil), http.StatusBadRequest)
71+
return
72+
}
6673
res, err := h.todoService.GetTodoByID(uint(id))
6774
if err != nil {
6875
h.log.Error("Handler: Service call failed for GetTodoByID", err, "todoID", id)

0 commit comments

Comments
 (0)