Unicorn with delicious cookie
Nous utilisons des cookies pour améliorer votre expérience de navigation. En savoir plus
Accepter
to the top
>
>
>
Challenge: can you spot an error in C++…

Challenge: can you spot an error in C++ code?

29 Jui 2022
Author:

PVS-Studio developers made an entertaining quiz for you. Try to quickly find a bug in a code fragment. If you spot an error - click on it.

Code analyzers restlessly search for errors. They can find even those that are hard to notice. We chose several code fragments in which PVS-Studio found errors. All fragments are from open-source projects.

We encourage you to compete with our analyzer and find these errors yourself! You'll see ten code fragments. If you manage to find an error in under 1 minute, you score one point.

The 1-minute limit is made on purpose. Otherwise you'll definitely find all errors — code fragments are short. Anyway, treat this quiz as a game, and not as a real test of your programming skills :)

When you find an error, highlight it with a mouse, and click "Answer". Sometimes there are several places in code with an error. You can highlight any of them and the answer will be correct. I'll explain it with an example.

case FuriHalSubGhzPreset2FSKDev476Async:
  preset_name = "FuriHalSubGhzPreset2FSKDev476Async";
  break;
  FURI_LOG_E(SUBGHZ_PARSER_TAG, "Unknown preset");
default:

This code fragment is taken from the FlipperZero project. The PVS-Studio analyzer warns us that part of the code is never executed: V779 [CWE-561, CERT-MSC12-C] Unreachable code detected. It is possible that an error is present. subghz_i.c 44

The developer was probably in a rush and used a logging macro after the break operator. Or this is a result of unsuccessful refactoring. Anyway, the error here is obvious. But what should we highlight?

On the one hand, we can choose the break operator as an answer. It's before the FURI_LOG_E and breaks the switch operator execution. So, the problem's here.

On the other hand, we can choose the logging macro. This is the unreachable code.

Which is the correct answer then? This is easy. In this case, whatever we highlight — the break operator or the FURI_LOG_E macro — will be the correct answer.

Now I think the rules are clear. Good luck: play the quiz.

Don't forget to share this quiz with your teammates! Have fun, and we wish you bugless code!

Popular related articles

S'abonner

Comments (0)

close comment form
close form

Remplissez le formulaire ci‑dessous en 2 étapes simples :

Vos coordonnées :

Étape 1
Félicitations ! Voici votre code promo !

Type de licence souhaité :

Étape 2
Team license
Enterprise licence
** En cliquant sur ce bouton, vous déclarez accepter notre politique de confidentialité
close form
Demandez des tarifs
Nouvelle licence
Renouvellement de licence
--Sélectionnez la devise--
USD
EUR
* En cliquant sur ce bouton, vous déclarez accepter notre politique de confidentialité

close form
La licence PVS‑Studio gratuit pour les spécialistes Microsoft MVP
close form
Pour obtenir la licence de votre projet open source, s’il vous plait rempliez ce formulaire
* En cliquant sur ce bouton, vous déclarez accepter notre politique de confidentialité

close form
I want to join the test
* En cliquant sur ce bouton, vous déclarez accepter notre politique de confidentialité

close form
check circle
Votre message a été envoyé.

Nous vous répondrons à


Si l'e-mail n'apparaît pas dans votre boîte de réception, recherchez-le dans l'un des dossiers suivants:

  • Promotion
  • Notifications
  • Spam