Pull to refresh
70.52

C *

General-purpose, imperative computer programming language, supporting structured programming, lexical variable scope and recursion, while a static type system prevents many unintended operations

Show first
Rating limit
Level of difficulty

How to send messages over sockets and create your own messanging protocols in C++

Level of difficulty Medium
Reading time 28 min
Views 2.8K

Network programming in C++ can be challenging. But even a greater challenge is to find educational content that will arm you with the knowledge on how to apply your networking skills in real applications.

In this article you can learn the basics of socket communication and many ways how you can design your internal messaging protocols.

Read more
Total votes 2: ↑2 and ↓0 +2
Comments 3

Setup of Qt Creator for programming and debugging of STM32 microcontrollers

Level of difficulty Medium
Reading time 9 min
Views 1.6K

Currently I am investigating firmware development for STM32 microcontrollers and I would like to share with you my experience for doing it in Qt Creator IDE.

There are a lot of IDEs, which are used for firmware development of STM32. Some of them, being quite comfortable, have restrictions for trial license. For example, the one of the most known IDE, IAR Embedded, suggests either a limited amount of product usage time (30 days) or the limited firmware size of 32 MB, which is not too much.

Within this scope of the publication, we investigate the method of setting up an environment that allows one to develop the full value of the STM32 firmware in Qt Creator.

Read more
Rating 0
Comments 0

Review of mini-book «60 terrible tips for a C++ developer»

Level of difficulty Easy
Reading time 6 min
Views 1.2K

I wrote a small e-book about terrible tips for C++ developers. Actually, it describes bad programming practices and explains why it's better to avoid them. However, every chapter of this mini-book starts with a terrible tip — just for fun.


60 terrible tips for a C++ developer


By the way, these tips may seem artificial but believe me, they are based on the real experience. In other words, the described terrible tips occur in developers' lives — that's why it's worth discussing them. First of all, this book will be useful for junior developers. But more skilled C++ developers can also find interesting and useful tips.


Even though it's a mini-book, it clearly does not fit into the Habr format. Too many words. So, I decided to write here the review. Here is the link to find the full version of the mini-book: 60 terrible tips for a C++ developer.


If you still hesitate whether to read it or not, below you will find a list of terrible tips that will be discussed in the mini-book.


View the terrible tips:

Read more →
Total votes 10: ↑7 and ↓3 +4
Comments 3

APRS. AFSK modulator from Flipper Zero

Level of difficulty Medium
Reading time 7 min
Views 4.7K

There is such an interesting data transfer protocol - APRS. A lot has already been told about him on the Internet. There will be no in-depth theoretical material here. This article will describe how to create your own "pocket" AFSK modulator. In the following articles there will be instructions for going on the air and for creating a simple demodulator. Which will allow you to accept APRS packages and display information on the display right on the street. Everything will be implemented for Flipper Zero. If you don't have this gadget yet, then don't worry and try everything on the great and terrible Arduino. It is very interesting to transmit information at a distance "with your own hands".

Read more
Total votes 3: ↑3 and ↓0 +3
Comments 2

Pixel image rotation

Level of difficulty Easy
Reading time 13 min
Views 1.2K

Brief problem formulation

The program accepts as input the absolute path to the image in the bmp extension and the path where you save the result of the work. Then, it rotates the image by 90 degrees counterclockwise. Afterwards, the program saves the new image.

The program is executed on C.

Read more
Total votes 7: ↑5 and ↓2 +3
Comments 0

Audio API Quick Start Guide: Playing and Recording Sound on Linux, Windows, FreeBSD and macOS

Reading time 35 min
Views 16K

Hearing is one of the few basic senses that we humans have along with the other our abilities to see, smell, taste and touch. If we couldn't hear, the world as we know it would be less interesting and colorful to us. It would be a total silence - a scary thing, even to imagine. And speaking makes our life so much fun, because what else can be better than talking to our friends and family? Also, we're able to listen to our favorite music wherever we are, thanks to computers and headphones. With the help of tiny microphones integrated into our phones and laptops we are now able to talk to the people around the world from any place with an Internet connection. But computer hardware alone isn't enough - it is computer software that really defines the way how and when the hardware should operate. Operating Systems provide the means for that to the apps that want to use computer's audio capabilities. In real use-cases audio data usually goes the long way from one end to another, being transformed and (un)compressed on-the-fly, attenuated, filtered, and so on. But in the end it all comes down to just 2 basic processes: playing the sound or recording it.

Today we're going to discuss how to make use of the API that popular OS provide: this is an essential knowledge if you want to create an app yourself which works with audio I/O. But there's just one problem standing on our way: there is no single API that all OS support. In fact, there are completely different API, different approaches, slightly different logic. We could just use some library which solves all those problems for us, but in that case we won't understand what's really going on under the hood - what's the point? But humans are built the way that we sometimes want to dig a little bit deeper, to learn a little bit more than what just lies on the surface. That's why we're going to learn the API that OS provide by default: ALSA (Linux), PulseAudio (Linux), WASAPI (Windows), OSS (FreeBSD), CoreAudio (macOS).

Read more
Rating 0
Comments 0

Alternate of Packed-Binary Time Format

Reading time 2 min
Views 2K

The Real-Time Clock (RTC) Calendar Registers in STM32 microcontrollers implemented in Binary Code Decimal format (BCD) i. e., every two digits are represented by one byte (low digit in 0-3 bits and high digit 4-7 bits). At least there are 5 bytes required to store date and time data in a such format. There are cases when memory allocation for time stamp might become critical, e. g., the events log keeping in an extern non-volatile memory IC. Here the memory value for a single event (event serial number, timestamp, event parameters, and its CRC) is fixed and can compose up to 16 bytes. The maximum quantity of the events increasing, and time spent on a single operation reducing (for reserved power sources as supercapacitors and electrolytic capacitors is critical) can be achieved with less memory amount required for the event field.

Read more
Rating 0
Comments 0

How PVS-Studio prevents rash code changes, example N2

Reading time 2 min
Views 570

Blender bug, PVS-Studio
When developers do make mistakes, it's often accidental or because the developers are in a hurry. These errors often make their way into small edits to the code. Let's review one of these cases: a developer fixes an error and introduces a new one simultaneously.

Read more →
Total votes 4: ↑2 and ↓2 0
Comments 0

Kernel Queue: The Complete Guide On The Most Essential Technology For High-Performance I/O

Reading time 65 min
Views 16K

When talking about high-performance software we probably think of server software (such as nginx) which processes millions requests from thousands clients in parallel. Surely, what makes server software work so fast is high-end CPU running with huge amount of memory and a very fast network link. But even then, the software must utilize these hardware resources at maximum efficiency level, otherwise it will end up wasting the most of the valuable CPU power for unnecessary kernel-user context switching or while waiting for slow I/O operations to complete.

Thankfully, the Operating Systems have a solution to this problem, and it's called kernel event queue. Server software and OS kernel use this mechanism together to achieve minimum latency and maximum scalability (when serving a very large number of clients in parallel). In this article we are going to talk about FreeBSD, macOS and kqueue, Linux and epoll, Windows and I/O Completion Ports. They all have their similarities and differences which we're going to discuss here. The goal of this article is for you to understand the whole mechanism behind kernel queues and to understand how to work with each API.

Read more
Total votes 7: ↑7 and ↓0 +7
Comments 1

PVS-Studio checks the code of Flipper Zero dolphin

Reading time 12 min
Views 1.6K

Flipper Zero + PVS-Studio


Flipper Zero is an open-source multi-tool for geeks and penetration testers. It so happened that the Flipper Zero project and the PVS-Studio analyzer crossed paths. A philosophical question: should we check the project, if the project developers have already started fixing errors? Let's try to do this.

Read more →
Total votes 6: ↑5 and ↓1 +4
Comments 0

Even small projects have bugs, or how PVS-Studio checked Blend2D

Reading time 11 min
Views 867

We often check large projects because it's easier to find bugs there. What if we try PVS-Studio on a small project? In this article we analyze Blend2D — a library for vector 2D graphics. Let's look at what we found.


0894_Blend2d/image1.png


Introduction


It's no secret that large projects have fascinating errors. It's not just "the larger the codebase is – the more errors we can find". It's also a known fact that the density of errors grows along with the codebase. That's why we love checking large projects — to treat you with a variety of "yummy" and tricky errors and typos. Besides, it's always interesting to search through a huge project with lots of dependencies, legacy code, and other stuff.


Today I'm moving away from this tradition. I decided to take a small project and see what PVS-Studio can find there. I chose Blend2D — branch master, commit c484790.

Read more →
Total votes 3: ↑2 and ↓1 +1
Comments 0

MISRA C: struggle for code quality and security

Reading time 11 min
Views 1.2K

A couple of years ago the PVS-Studio analyzer got its first diagnostic rules to check program code compliance with the MISRA C and MISRA C++ standards. We collected feedback and saw that our clients were interested in using the analyzer to check their projects for MISRA compliance. So, we decided to further develop the analyzer in this direction. The article covers the MISRA C/C++ standard and the MISRA Compliance report. It also shows what we already managed to do and what we plan to achieve by the end of the year.


0866_MISRA_C/image1.png

Read more →
Rating 0
Comments 0

Why do you need the MISRA Compliance report and how to generate one in PVS-Studio?

Reading time 5 min
Views 834

If you are strongly interested in MISRA and would like to understand whether your project meets one of the MISRA association's standards, there is a solution. It's name is MISRA Compliance. PVS-Studio has recently learned how to generate the MISRA Compliance report. This article describes how you can use this feature. This can make somebody's life better.

Read more
Rating 0
Comments 3

Linux kernel turns 30: congratulations from PVS-Studio

Reading time 6 min
Views 1.7K

On August 25th, 2021, the Linux kernel celebrated its 30th anniversary. Since then, it's changed a lot. We changed too. Nowadays, the Linux kernel is a huge project used by millions. We checked the kernel 5 years ago. So, we can't miss this event and want to look at the code of this epic project again.

Read more
Total votes 2: ↑2 and ↓0 +2
Comments 0

Static analysis protects your code from time bombs

Reading time 2 min
Views 1K

0848_Timebomb/image2.png
Static code analysis allows you to identify and eliminate many defects at an early stage. Moreover, it's possible to detect dormant errors that don't show themselves when they appear. They can cause many problems in the future and it requires many hours of debugging to detect them. Let's look at an example of such a dormant error.

Read more →
Total votes 2: ↑2 and ↓0 +2
Comments 0

A Beautiful Error in the Implementation of the String Concatenation Function

Reading time 4 min
Views 1.3K

We, the PVS-Studio static code analyzer developers, have a peculiar view on beauty. On the beauty of bugs. We like to find grace in errors, examine them, try to guess how they appeared. Today we have an interesting case when the concepts of length and size got mixed up in the code.


0845_LFortran_strcat/image2.png

Read more →
Total votes 2: ↑1 and ↓1 0
Comments 0

Authors' contribution