Is this wiring safe and is it according to code?
There is one safety issue here

It appears that the original installer took the ground wire from the 12/3 cable, looped it around one switch ground screw, then attached it to the other switch ground screw.  This grounds the switch yokes fine, but leaves the (metal) box ungrounded save through screw threads.  The solution to this is to cut off the existing ground wire with some slack left, then nut it to pigtails to the switch ground screws and a ground screw (10-32) into the provided hole in the back of the box.

While you're at it, you should wrap the white wire with black tape to make it crystal clear to the next bloke looking inside the box that it's hot and not neutral.

As to Code...this used to be OK, but not any longer

Back before the 2011 NEC, an "old style" switch loop like this was permitted by the Code -- a single pole switch only needs always-hot and switched-hot, so a 12/2 cable could be used for a single switch or a 12/3 for a pair of switches sharing a hot feed, as you see here.

However, due to the increasing prevalence of remote-controlled switches, motion sensors, timers, and advanced dimmers, all of which benefit from having a neutral at the switch box to provide power to the electronics inside, the 2011 NEC added 404.2(C) to ensure that the neutral was available for such devices, in lieu of them powering themselves via a hack such as using the ground wire as the return path or trickling their operating current through the load (quoted from the 2017 NEC, save for vernacular terms in [square brackets]):


  (C) Switches Controlling Lighting Loads. The grounded
  circuit conductor [neutral] for the controlled lighting circuit shall be
  installed at the location where switches control lighting loads
  that are supplied by a grounded general-purpose branch circuit
  serving bathrooms, hallways, stairways, or rooms suitable for
  human habitation or occupancy as defined in the applicable
  building code. Where multiple switch locations control the
  same lighting load such that the entire floor area of the room
  or space is visible from the single or combined switch locations,
  the grounded circuit conductor  [neutral] shall only be required at one
  location. A grounded conductor  [neutral] shall not be required to be
  installed at lighting switch locations under any of the following
  conditions:
  
  (1) Where conductors enter the box enclosing the switch
  through a raceway, provided that the raceway is large
  enough for all contained conductors, including a grounded conductor [neutral] 
  
  (2) Where the box enclosing the switch is accessible for the
  installation of an additional or replacement cable without
  removing finish materials
  
  (3) Where snap switches with integral enclosures comply with
  300.15(E)
  
  (4) Where lighting in the area is controlled by automatic
  means
  
  (5) Where a switch controls a receptacle load
  
  The grounded conductor  [neutral] shall be extended to any switch
  location as necessary and shall be connected to switching devices that require line-to-neutral voltage to operate the electronics of the switch in the standby mode and shall meet the
  requirements of 404.22.
  
  Exception: The connection requirement shall become effective on January 1, 2020. It shall not apply to replacement or retrofit switches installed in locations prior to local adoption of 404.2(C) and where the
  grounded conductor  [neutral] cannot be extended without removing finish materials. The number of electronic lighting control switches on a branch
  circuit shall not exceed five, and the number connected to any feeder on
  the load side of a system or main bonding jumper shall not exceed 25.
  For the purpose of this exception, a neutral busbar, in compliance with
  200.2(B) and to which a main or system bonding jumper is connected
  shall not be limited as to the number of electronic lighting control
  switches connected.
  
  Informational Note: The provision for a (future) grounded
  conductor [neutral]  is to complete a circuit path for electronic lighting
  control devices.


and the 2017 NEC followed up on this with the addition of 404.22, which provides a phase-out for the hack of returning current via ground in lieu of neutral:


  404.22 Electronic Lighting Control Switches. Electronic lighting control switches shall be listed. Electronic lighting control
  switches shall not introduce current on the equipment grounding conductor  [ground] during normal operation. The requirement to
  not introduce current on the equipment grounding conductor [ground] 
  shall take effect on January 1, 2020.
  
  Exception: Electronic lighting control switches that introduce current on the equipment grounding conductor [ground]  shall be permitted for applications covered by 404.2(C), Exception. Electronic lighting control switches that introduce current on the equipment grounding conductor [ground] shall be listed and marked for use in replacement or retrofit applications only.