Skip to main content
deleted 895 characters in body
Source Link
Harith
  • 9.8k
  • 1
  • 14
  • 50

Also note that:

switch (expr->operator) {
    case '+':
        result = b->number + a->number;
        break;
    case '-':
        result = b->number - a->number;
        break;
    case '/':
        result = b->number / a->number;
        break;
    case '*':
        result = b->number * a->number;
        break;
    case '^':
        result = pow(b->number, a->number);
        break;
}

all these operations can cause overflow, which would invoke undefined behavior. You might be interested in seeing: Checked integer arithmetic in the prospect of C23, namely these functions:

#include <stdckdint.h>
bool ckd_add(type1 *result, type2 a, type3 b);
bool ckd_sub(type1 *result, type2 a, type3 b);
bool ckd_mul(type1 *result, type2 a, type3 b);

Also note that:

switch (expr->operator) {
    case '+':
        result = b->number + a->number;
        break;
    case '-':
        result = b->number - a->number;
        break;
    case '/':
        result = b->number / a->number;
        break;
    case '*':
        result = b->number * a->number;
        break;
    case '^':
        result = pow(b->number, a->number);
        break;
}

all these operations can cause overflow, which would invoke undefined behavior. You might be interested in seeing: Checked integer arithmetic in the prospect of C23, namely these functions:

#include <stdckdint.h>
bool ckd_add(type1 *result, type2 a, type3 b);
bool ckd_sub(type1 *result, type2 a, type3 b);
bool ckd_mul(type1 *result, type2 a, type3 b);
deleted 8 characters in body
Source Link
Harith
  • 9.8k
  • 1
  • 14
  • 50

all these operations can cause integer overflow, which would invoke undefined behavior. You might be interested in seeing: Checked integer arithmetic in the prospect of C23, namely these functions:

all these operations can cause integer overflow, which would invoke undefined behavior. You might be interested in seeing: Checked integer arithmetic in the prospect of C23, namely these functions:

all these operations can cause overflow, which would invoke undefined behavior. You might be interested in seeing: Checked integer arithmetic in the prospect of C23, namely these functions:

deleted 20 characters in body
Source Link
Harith
  • 9.8k
  • 1
  • 14
  • 50

You are computing the length of num_buf thrice in parse_to_postfix(). Consider using an extra variable to save the length.


switch (expr->operator) {
                case '+':
                    result = b->number + a->number;
                    break;
                case '-':
                    result = b->number - a->number;
                    break;
                case '/':
                    result = b->number / a->number;
                    break;
                case '*':
                    result = b->number * a->number;
                    break;
                case '^':
                    result = pow(b->number, a->number);
                    break;
            }

all these operations, besides division, can cause integer overflow, which would invoke undefined behavior. You might be interested in seeing: Checked integer arithmetic in the prospect of C23, namely these functions:

#include <stdckdint.h>
bool ckd_add(type1 *result, type2 a, type3 b);
bool ckd_sub(type1 *result, type2 a, type3 b);
bool ckd_mul(type1 *result, type2 a, type3 b);
````
switch (expr->operator) {
                case '+':
                    result = b->number + a->number;
                    break;
                case '-':
                    result = b->number - a->number;
                    break;
                case '/':
                    result = b->number / a->number;
                    break;
                case '*':
                    result = b->number * a->number;
                    break;
                case '^':
                    result = pow(b->number, a->number);
                    break;
            }

all these operations, besides division, can cause integer overflow, which would invoke undefined behavior. You might be interested in seeing: Checked integer arithmetic in the prospect of C23, namely these functions:

#include <stdckdint.h>
bool ckd_add(type1 *result, type2 a, type3 b);
bool ckd_sub(type1 *result, type2 a, type3 b);
bool ckd_mul(type1 *result, type2 a, type3 b);
````

You are computing the length of num_buf thrice in parse_to_postfix(). Consider using an extra variable to save the length.


switch (expr->operator) {
    case '+':
        result = b->number + a->number;
        break;
    case '-':
        result = b->number - a->number;
        break;
    case '/':
        result = b->number / a->number;
        break;
    case '*':
        result = b->number * a->number;
        break;
    case '^':
        result = pow(b->number, a->number);
        break;
}

all these operations can cause integer overflow, which would invoke undefined behavior. You might be interested in seeing: Checked integer arithmetic in the prospect of C23, namely these functions:

#include <stdckdint.h>
bool ckd_add(type1 *result, type2 a, type3 b);
bool ckd_sub(type1 *result, type2 a, type3 b);
bool ckd_mul(type1 *result, type2 a, type3 b);
Source Link
Harith
  • 9.8k
  • 1
  • 14
  • 50
Loading