~ubuntu-branches/ubuntu/saucy/libvirt/saucy

« back to all changes in this revision

Viewing changes to src/util/viralloc.c

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2013-05-02 10:21:49 UTC
  • mfrom: (1.2.18)
  • Revision ID: package-import@ubuntu.com-20130502102149-2ajbdvo0ii64m2qd
Tags: 1.0.5-0ubuntu1
* New upstream release: 
  + Dropped patches:
    - debian/patches/fix-virterror-namechange
    - debian/patches/apparmor-use-apparmor-setfdlabel
    - debian/patches/prevent-lxc-shutdown-host.patch
    - debian/patches/apparmor-no-need-to-check-security-model
    - debian/patches/nonblock-fix.patch
   + Refreshed patches:
    - debian/patches/9002-better_default_uri_virsh.patch
    - debian/patches/enable-kvm-spice.patch
    - debian/patches/patch-qemuMonitorTextGetMigrationStatus-to-intercept.patch
 * debian/patches/Add-sanitytest.py.patch: Add patch to fix missing sanitytest.py
   when building the testsuite.
 * debian/libvirt-dev.install: dont't ship files for static linking.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 * viralloc.c: safer memory allocation
3
3
 *
4
 
 * Copyright (C) 2010-2012 Red Hat, Inc.
 
4
 * Copyright (C) 2010-2013 Red Hat, Inc.
5
5
 * Copyright (C) 2008 Daniel P. Berrange
6
6
 *
7
7
 * This library is free software; you can redistribute it and/or
74
74
    testMallocNext++;
75
75
    return fail;
76
76
}
 
77
 
 
78
#else
 
79
 
 
80
void virAllocTestOOM(int n ATTRIBUTE_UNUSED,
 
81
                     int m ATTRIBUTE_UNUSED)
 
82
{
 
83
    /* nada */
 
84
}
 
85
 
 
86
int virAllocTestCount(void)
 
87
{
 
88
    return 0;
 
89
}
 
90
 
 
91
void virAllocTestInit(void)
 
92
{
 
93
    /* nada */
 
94
}
 
95
 
 
96
void virAllocTestHook(void (*func)(int, void*) ATTRIBUTE_UNUSED,
 
97
                      void *data ATTRIBUTE_UNUSED)
 
98
{
 
99
    /* nada */
 
100
}
77
101
#endif
78
102
 
79
103
 
328
352
 * @size:     the size of one element in bytes
329
353
 * @at:       index within array where new elements should be deleted
330
354
 * @countptr: variable tracking number of elements currently allocated
331
 
 * @remove:   number of elements to remove
 
355
 * @toremove: number of elements to remove
332
356
 * @inPlace:  false if we should shrink the allocated memory when done,
333
357
 *            true if we should assume someone else will do that.
334
358
 *
341
365
 */
342
366
int
343
367
virDeleteElementsN(void *ptrptr, size_t size, size_t at,
344
 
                   size_t *countptr, size_t remove,
 
368
                   size_t *countptr, size_t toremove,
345
369
                   bool inPlace)
346
370
{
347
 
    if (at + remove > *countptr) {
348
 
        VIR_WARN("out of bounds index - count %zu at %zu remove %zu",
349
 
                 *countptr, at, remove);
 
371
    if (at + toremove > *countptr) {
 
372
        VIR_WARN("out of bounds index - count %zu at %zu toremove %zu",
 
373
                 *countptr, at, toremove);
350
374
        return -1;
351
375
    }
352
376
 
355
379
     * already been cleared.
356
380
    */
357
381
    memmove(*(char**)ptrptr + (size * at),
358
 
            *(char**)ptrptr + (size * (at + remove)),
359
 
            size * (*countptr - remove - at));
 
382
            *(char**)ptrptr + (size * (at + toremove)),
 
383
            size * (*countptr - toremove - at));
360
384
    if (inPlace)
361
 
        *countptr -= remove;
 
385
        *countptr -= toremove;
362
386
    else
363
 
        virShrinkN(ptrptr, size, countptr, remove);
 
387
        virShrinkN(ptrptr, size, countptr, toremove);
364
388
    return 0;
365
389
}
366
390
 
367
391
/**
368
 
 * Vir_Alloc_Var:
 
392
 * virAllocVar:
369
393
 * @ptrptr: pointer to hold address of allocated memory
370
394
 * @struct_size: size of initial struct
371
395
 * @element_size: size of array elements