In this article, a safety-critical controller and a novel algorithm based on a quadratic program for a class of planar quadrotors are proposed to ensure obstacle avoidance and target attainment. First, we define a circular safe region and design a safety-critical controller based on the control barrier function. Also, the designed controller can guarantee that the planar quadrotor remains within the safe region and eventually reaches the center of the safe region. Second, we design an algorithm to generate a sequence of safe regions that progressively approach the target point. With the designed controller, the planar quadrotor gradually reaches the center of each safe region and eventually reaches the target point. Finally, the effectiveness of the proposed controller and algorithm is verified through two simulation experiments.