News for hackers. Stuff that matters.
Re:Parse, Don't Validate (For C) by Gibbon1 on Sunday July 13, 2025 @04:41AM (#44548631)
I'm with you, don't do crap like that. Always return a valid object.

  email_t theEmail = parseEmail(untrustedInput);
  if (theEmail.error != PARSE_OK) {
    return error;
  }
Re:Parse, Don't Validate (For C) by mrkeen on Sunday July 13, 2025 @05:08AM (#44548744)
This is validate.

You made an email-or-error type and named it email_t and then manually checked it.

PDV returns an non-error-email type from the check method.

Re:Parse, Don't Validate (For C) by ykonstant on Sunday July 13, 2025 @11:02AM (#44550915)
I don't understand; what is your suggested solution?
Re:Parse, Don't Validate (For C) by mrkeen on Sunday July 13, 2025 @11:52AM (#44551286)
I'm not smart enough to suggest a fix here, I'm just pointing out that this article is not the PdV from the well known article.

But I can spot when code is doing exactly what the cited article says not to do,

This line is the "validate" in the expression "parse, don't validate":

  if (theEmail.error != PARSE_OK)
You might like it, but that's not my business. Maybe this C article should have been "parse, then validate".

You'd be better off reading the original: https://lexi-lambda.github.io/blog/2019/11/05/parse-don-t-va...

Re:Parse, Don't Validate (For C) by teo_zero on Sunday July 13, 2025 @12:47PM (#44551667)
parseEmail() should either return a valid email, or not return at all; whether that means panic, exit, or jump to an error handler... is left to the implementer