Safeguarding oneself from bad actions while fasting is from the perfection of fasting
BUKHARI 1903:
from Abū Hurayrah —
The Prophet ﷺ said, "Whoever does not give up forged speech and evil actions, Allah is not in need of his leaving his food and drink (i.e. Allah will not accept his fasting.)"
البخاري ١٩٠٣:
عن ابو هريره —
قَالَ رَسُولُ اللَّهِ ﷺ مَنْ لَمْ يَدَعْ قَوْلَ الزُّورِ وَالْعَمَلَ بِهِ فَلَيْسَ لِلَّهِ حَاجَةٌ فِي أَنْ يَدَعَ طَعَامَهُ وَشَرَابَهُ