﻿# V121\. Implicit conversion of the type of 'new' operator's argument to size\_t type\.


> This rule belongs to the "Diagnosis of 64\\\-bit errors" group\\\. The rules in this group are no longer developed and may be disabled in the future\\\. If you use these rules, please \[contact our support team\]\(https://pvs\-studio\.com/en/about\-feedback/\)—we will help you find a replacement or suggest an alternative solution\\\.

The analyzer detected a potential error related to calling the operator new\. A value of a non\-memsize type is passed to the operator "new" as an argument\. The operator new takes values of the type size\_t, and passing a 32\-bit actual argument may signal a potential overflow that may occur when calculating the memory amount being allocated\.

Here is an example: 

```cpp
unsigned a = 5;
unsigned b = 1024;
unsigned c = 1024;
unsigned d = 1024;
char *ptr = new char[a*b*c*d]; //V121
```

Here you may see an overflow occurring when calculating the expression "a\*b\*c\*d"\. As a result, the program allocates less memory than it should\. To correct the code, use the type size\_t:

```cpp
size_t a = 5;
size_t b = 1024;
size_t c = 1024;
size_t d = 1024;
char *ptr = new char[a*b*c*d]; //Ok
```

The error will not be diagnosed if the value of the argument is defined as a safe 32\-bit constant value\. Here is an example of safe code:

```cpp
char *ptr = new char[100]; 
const int size = 3*3;
char *p2 = new char[size];
```

This warning message is similar to the warning [V106](https://pvs-studio.com/en/docs/warnings/v106/)\.

Additional materials on this topic:

1. 64\-bit Lessons\. Lesson 17\. Pattern 9\. [Mixed arithmetic](https://pvs-studio.com/en/blog/lessons/0017/)\.