Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (Cyborg)
  • No Skin
Collapse
Brand Logo

CIRCLE WITH A DOT

  1. Home
  2. Uncategorized
  3. Spot the error?

Spot the error?

Scheduled Pinned Locked Moved Uncategorized
cpp
2 Posts 1 Posters 7 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • charette@mstdn.caC This user is from outside of this forum
    charette@mstdn.caC This user is from outside of this forum
    charette@mstdn.ca
    wrote last edited by
    #1

    Spot the error?

    std::string val = get_string_value();
    if (not val.empty())
    {
    if (val[0] < 0 or val[0] > 9)
    {
    std::cout << "must start with a digit" << std::endl;

    #cpp

    charette@mstdn.caC 1 Reply Last reply
    1
    0
    • R relay@relay.mycrowd.ca shared this topic
    • charette@mstdn.caC charette@mstdn.ca

      Spot the error?

      std::string val = get_string_value();
      if (not val.empty())
      {
      if (val[0] < 0 or val[0] > 9)
      {
      std::cout << "must start with a digit" << std::endl;

      #cpp

      charette@mstdn.caC This user is from outside of this forum
      charette@mstdn.caC This user is from outside of this forum
      charette@mstdn.ca
      wrote last edited by
      #2

      And in case anyone tries to bring it up, keywords like "and", "not", "or" and many more have been part of the C standard since 1994 and C++ since 1998.

      That is not a bug!

      But it is true that many C and C++ developers don't know this is perfectly valid.

      The code above contains a very real bug I spent time hunting down tonight in that large codebase I've been looking into recently.

      1 Reply Last reply
      1
      0
      • R relay@relay.infosec.exchange shared this topic
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups