Wouldn’t the intention of baptism right before death count for something? In other words, if an adult person were baptized expressly for the purpose of washing away original sin and personal sins and asked to undergo the Sacrament of Baptism before death just so they might be saved and go to Heaven, but were not sincere about repentance for the mortal sins they had committed during their lives, would the Sacrament in and of itself guarantee salvation? When an infant is baptized, it washes away their original sin; but they will surely commit many other venial and mortal sins during their life which they must repent for (the mortal sins at least) in the Sacrament of Confession. They might also have received the Sacrament of the Eucharist during their lifetime.
But a person who receives baptism on his deathbed may not have ever confessed their mortal sins or received the Eucharist,
With Confession, when a person is gravely ill, a priest will got to the hospital/home to hear confession and bring Eucharist. So for example in a case where maybe a patient is truly repentant and decides that he/she wants to be baptised, they could do all 3 in one day, Baptism, Confession and receive the Eucharist.
**
and may not even be sincere** in receiving Baptism. Wouldn’t this make a difference?
Definitely if the baptism was insincere, just because you knew your time was up and you wanted to hedge your bets, then you are only fooling yourself and God knows what is written on every human heart.