Safety-Aware Task Composition for Discrete and Continuous Reinforcement Learning