Linux malloc segmentation fault missing

خرید بک لینک

The included program should produce a segmentation fault in Linux, but it doesn't.

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

/* This program should produce a segmentation error */
/* but it doesn't */

/* Therefore memory bounds are not being checked by the keel */

typedef struct {
   double x;
   } blkfmt;

int main()
   {
   blkfmt *blk;
   unsigned char *p;
   blk = (blkfmt *) malloc(sizeof(blkfmt));
   p = (unsigned char *) blk + 16384;
   /* this assignment should produce a segmentation error */
   *p = (unsigned char) 0xff;
   /* this print statement should produce a segmentation error */
   printf("%02x %dn", *p, sizeof(blkfmt));
   free(blk);
   retu(0);
   } /* main */

----------------- make file -------------------------------

OBJ=bug.o

CC=gcc

CFLAGS=-c -Wall -O2

LDFLAGS=

bug: $(OBJ) $(CC) -Wall -O2 $(OBJ) -o bug $(LDFLAGS)

bug.o: bug.c $(CC) $(CFLAGS) bug.c

clean: rm -f bug $(OBJ)

Recent Questions...

ما را در سایت Recent Questions دنبال می‌کنید

برچسب: نویسنده: استخدام کار بازدید: 265 تاريخ: جمعه 18 تير 1395 ساعت: 4:13

صفحه بندی